Skip to content

Commit cef1e78

Browse files
committed
Simplify WASM CI
1 parent 7d0eb2e commit cef1e78

4 files changed

Lines changed: 56 additions & 17 deletions

File tree

.github/workflows/other.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ jobs:
118118
wasi-${{ runner.os }}-${{ env.GHC_WASM_META_REV }}-flavour-${{ matrix.ghc }}-
119119
- name: Build
120120
run: |
121-
mv cabal.project.wasi cabal.project.local
122121
wasm32-wasi-cabal build --enable-tests all
123122
wasm32-wasi-cabal list-bin test:tests
124123
- name: Test

cabal.project.wasi

Lines changed: 0 additions & 12 deletions
This file was deleted.

zlib/Codec/Compression/Zlib.hs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ module Codec.Compression.Zlib (
2121

2222
-- * Simple compression and decompression
2323
compress,
24+
compressFromHandle,
2425
decompress,
26+
decompressFromHandle,
2527
DecompressError(..),
2628

2729
-- * Extended API with control over compression parameters
@@ -60,7 +62,8 @@ module Codec.Compression.Zlib (
6062
import Data.ByteString.Lazy (ByteString)
6163

6264
import qualified Codec.Compression.Zlib.Internal as Internal
63-
import Codec.Compression.Zlib.Internal hiding (compress, decompress)
65+
import Codec.Compression.Zlib.Internal (DecompressParams, CompressParams, DecompressError, defaultCompressParams, defaultDecompressParams, CompressionLevel, defaultCompression, noCompression, bestSpeed, bestCompression, compressionLevel, Method, deflateMethod, WindowBits, defaultWindowBits, windowBits, MemoryLevel, defaultMemoryLevel, minMemoryLevel, maxMemoryLevel, memoryLevel, CompressionStrategy, defaultStrategy, filteredStrategy, huffmanOnlyStrategy, rleStrategy, fixedStrategy)
66+
import System.IO (Handle)
6467

6568

6669
-- | Decompress a stream of data in the zlib format,
@@ -75,14 +78,16 @@ import Codec.Compression.Zlib.Internal hiding (compress, decompress)
7578
decompress :: ByteString -> ByteString
7679
decompress = decompressWith defaultDecompressParams
7780

81+
decompressFromHandle :: Handle -> IO ByteString
82+
decompressFromHandle = Internal.decompressFromHandle Internal.zlibFormat defaultDecompressParams
7883

7984
-- | Like 'Codec.Compression.Zlib.decompress' but with the ability to specify various decompression
8085
-- parameters. Typical usage:
8186
--
8287
-- > decompressWith defaultCompressParams { ... }
8388
--
8489
decompressWith :: DecompressParams -> ByteString -> ByteString
85-
decompressWith = Internal.decompress zlibFormat
90+
decompressWith = Internal.decompress Internal.zlibFormat
8691

8792

8893
-- | Compress a stream of data into the zlib format.
@@ -97,6 +102,8 @@ decompressWith = Internal.decompress zlibFormat
97102
compress :: ByteString -> ByteString
98103
compress = compressWith defaultCompressParams
99104

105+
compressFromHandle :: Handle -> IO ByteString
106+
compressFromHandle = Internal.compressFromHandle Internal.zlibFormat defaultCompressParams
100107

101108
-- | Like 'Codec.Compression.Zlib.compress' but with the ability to specify various compression
102109
-- parameters. Typical usage:

zlib/Codec/Compression/Zlib/Internal.hs

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{-# LANGUAGE CPP, RankNTypes, DeriveDataTypeable, BangPatterns #-}
22
{-# LANGUAGE DeriveGeneric #-}
33
{-# LANGUAGE Trustworthy #-}
4+
{-# LANGUAGE LambdaCase #-}
5+
{-# LANGUAGE ScopedTypeVariables #-}
46
-----------------------------------------------------------------------------
57
-- |
68
-- Copyright : (c) 2006-2015 Duncan Coutts
@@ -15,7 +17,9 @@ module Codec.Compression.Zlib.Internal (
1517

1618
-- * Pure interface
1719
compress,
20+
compressFromHandle,
1821
decompress,
22+
decompressFromHandle,
1923

2024
-- * Monadic incremental interface
2125
-- $incremental-compression
@@ -75,8 +79,8 @@ module Codec.Compression.Zlib.Internal (
7579
) where
7680

7781
import Prelude hiding (length)
78-
import Control.Monad (when)
79-
import Control.Exception (Exception, throw, assert)
82+
import Control.Monad (when, (>=>))
83+
import Control.Exception (Exception, throw, assert, throwIO)
8084
import Control.Monad.ST.Lazy hiding (stToIO)
8185
import Control.Monad.ST.Strict (stToIO)
8286
import qualified Control.Monad.ST.Unsafe as Unsafe (unsafeIOToST)
@@ -95,6 +99,8 @@ import GHC.IO (noDuplicate)
9599
import qualified Codec.Compression.Zlib.Stream as Stream
96100
import Codec.Compression.Zlib.ByteStringCompat (mkBS, withBS)
97101
import Codec.Compression.Zlib.Stream (Stream)
102+
import System.IO (Handle, hIsSeekable, hSeek, SeekMode(..))
103+
import Data.ByteString.Builder.Extra (defaultChunkSize)
98104

99105
-- | The full set of parameters for compression. The defaults are
100106
-- 'defaultCompressParams'.
@@ -487,6 +493,32 @@ compress format params = foldCompressStreamWithInput
487493
compressST format params = compressStreamST format params
488494
compressIO format params = compressStreamIO format params
489495

496+
compressFromHandle
497+
:: forall acc.
498+
Stream.Format
499+
-> CompressParams
500+
-> Handle
501+
-> (acc -> S.ByteString -> IO acc)
502+
-> acc
503+
-> IO acc
504+
compressFromHandle format params hndl cons nil = go nil (compressStreamIO format params)
505+
where
506+
go :: acc -> CompressStream IO -> IO acc
507+
go !acc = \case
508+
CompressInputRequired next ->
509+
S.hGetSome hndl defaultChunkSize >>= next >>= go acc
510+
CompressOutputAvailable outchunk next -> do
511+
acc' <- acc `cons` outchunk
512+
next >>= go acc'
513+
CompressStreamEnd ->
514+
pure acc
515+
516+
-- foldCompressStream
517+
-- (S.hGetSome hndl defaultChunkSize >>=)
518+
-- undefined -- (fmap . L.chunk)
519+
-- (pure L.empty)
520+
-- (compressStreamIO format params)
521+
490522
-- | Chunk size must fit into t'CUInt'.
491523
compressStream :: Stream.Format -> CompressParams -> S.ByteString
492524
-> Stream (CompressStream Stream)
@@ -621,6 +653,19 @@ decompress format params = foldDecompressStreamWithInput
621653
decompressST format params = decompressStreamST format params
622654
decompressIO format params = decompressStreamIO format params
623655

656+
decompressFromHandle :: Stream.Format -> DecompressParams -> Handle -> IO L.ByteString
657+
decompressFromHandle format params hndl = foldDecompressStream
658+
(S.hGetSome hndl defaultChunkSize >>=)
659+
(fmap . L.chunk)
660+
(\unconsumed -> do
661+
isSeekable <- hIsSeekable hndl
662+
when isSeekable $
663+
hSeek hndl RelativeSeek (toInteger $ S.length unconsumed)
664+
pure L.empty
665+
)
666+
throwIO
667+
(decompressStreamIO format params)
668+
624669
-- | Chunk size must fit into t'CUInt'.
625670
decompressStream :: Stream.Format -> DecompressParams
626671
-> Bool -> S.ByteString

0 commit comments

Comments
 (0)