zlib-bytes 0.1.0.1 → 0.1.0.2
raw patch · 7 files changed
+155/−141 lines, 7 filessetup-changednew-uploaderPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- CHANGELOG.md +8/−2
- Setup.hs +0/−2
- cbits/trees.h +0/−1
- src/Zlib.hs +2/−2
- src/Zlib/Raw.hs +66/−60
- test/Main.hs +7/−11
- zlib-bytes.cabal +72/−63
CHANGELOG.md view
@@ -1,5 +1,11 @@ # Revision history for zlib-bytes -## 0.1.0.0 -- YYYY-mm-dd+## 0.1.0.2 -- 2024-02-01 -* First version. Released on an unsuspecting world.+* Update package metadata.++## 0.1.0.1 -- 2024-01-10++## 0.1.0.0 -- 2021-10-21++* First version.
− Setup.hs
@@ -1,2 +0,0 @@-import Distribution.Simple-main = defaultMain
cbits/trees.h view
@@ -125,4 +125,3 @@ 32, 48, 64, 96, 128, 192, 256, 384, 512, 768, 1024, 1536, 2048, 3072, 4096, 6144, 8192, 12288, 16384, 24576 };-
src/Zlib.hs view
@@ -1,11 +1,11 @@ module Zlib ( decompress- , ZlibError(..)+ , ZlibError (..) ) where import Data.Bytes (Bytes) import Data.Bytes.Chunks (Chunks)-import Zlib.Raw (runZlib, ZlibError(..))+import Zlib.Raw (ZlibError (..), runZlib) import qualified Zlib.Raw as Raw
src/Zlib/Raw.hs view
@@ -1,49 +1,45 @@-{-# language BangPatterns #-}-{-# language CApiFFI #-}-{-# language FlexibleContexts #-}-{-# language GeneralizedNewtypeDeriving #-}-{-# language MagicHash #-}-{-# language MultiParamTypeClasses #-}-{-# language PatternSynonyms #-}-{-# language RankNTypes #-}-{-# language TypeApplications #-}-{-# language UnboxedTuples #-}-{-# language UnliftedFFITypes #-}-{-# language ViewPatterns #-}+{-# LANGUAGE BangPatterns #-}+{-# LANGUAGE CApiFFI #-}+{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE GeneralizedNewtypeDeriving #-}+{-# LANGUAGE MagicHash #-}+{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE PatternSynonyms #-}+{-# LANGUAGE RankNTypes #-}+{-# LANGUAGE TypeApplications #-}+{-# LANGUAGE UnboxedTuples #-}+{-# LANGUAGE UnliftedFFITypes #-}+{-# LANGUAGE ViewPatterns #-} module Zlib.Raw ( Zlib , runZlib , decompress- , ZlibError(..)+ , ZlibError (..) ) where import Control.Exception (Exception)+import Control.Monad.Except (ExceptT, MonadError (catchError, throwError), runExceptT)+import Control.Monad.Reader (ReaderT, asks, runReaderT)+import Control.Monad.ST (ST, runST) import Control.Monad.Trans.Class (lift)-import Control.Monad.Except (ExceptT, runExceptT)-import Control.Monad.Except (MonadError(throwError,catchError))-import Control.Monad.Reader (ReaderT, runReaderT, asks)-import Control.Monad.ST (runST)-import Control.Monad.ST (ST) import Data.Bytes (Bytes)-import Data.Bytes.Chunks (Chunks(ChunksCons,ChunksNil))-import Data.Primitive.ByteArray (MutableByteArray(MutableByteArray))-import Data.Primitive.ByteArray (newPinnedByteArray)+import Data.Bytes.Chunks (Chunks (ChunksCons, ChunksNil))+import Data.Primitive.ByteArray (MutableByteArray (MutableByteArray), newPinnedByteArray) import Data.Word (Word8)-import Foreign.C.Types (CInt(CInt))+import Foreign.C.Types (CInt (CInt)) import Foreign.Ptr (Ptr)-import GHC.Exts (MutableByteArray#,touch#)-import GHC.IO (IO(IO),unsafeIOToST)+import GHC.Exts (MutableByteArray#, touch#)+import GHC.IO (IO (IO), unsafeIOToST) import qualified Data.Bytes as Bytes import qualified Data.Bytes.Chunks as Chunks import qualified Data.Primitive.ByteArray as BA - -- FIXME there are kinda two monads: ZlibCompress, ZlibDecompress -- so far, I've only done the latter-newtype Zlib s a = Zlib { unZlib :: ReaderT (Stream s) (ExceptT ZlibError (ST s)) a }- deriving(Functor, Applicative, Monad)+newtype Zlib s a = Zlib {unZlib :: ReaderT (Stream s) (ExceptT ZlibError (ST s)) a}+ deriving (Functor, Applicative, Monad) instance MonadError ZlibError (Zlib s) where throwError exn = Zlib (throwError exn)@@ -56,7 +52,7 @@ -- TODO: In GHC 8.10+, use with# instead of touch# so that the -- noinline pragma is not needed. runZlib :: (forall s. Zlib s a) -> Bytes -> Either ZlibError a-{-# noinline runZlib #-}+{-# NOINLINE runZlib #-} runZlib action inp = runST $ runExceptT $ do let pinnedInp = Bytes.pin inp stream <- newStream pinnedInp@@ -65,7 +61,6 @@ Bytes.touch pinnedInp pure v - ------------ Idiomatic FFI Calls ------------ type PreZlib s a = ExceptT ZlibError (ST s) a@@ -78,9 +73,10 @@ inpLen = Bytes.length pinnedInp MutableByteArray stream# <- newPinnedByteArray sizeofStream ret <- lift . unsafeIOToST $ initDecompress stream# inpP inpLen- let stream = Stream- { unStream = MutableByteArray stream#- }+ let stream =+ Stream+ { unStream = MutableByteArray stream#+ } case ret of Z_OK -> pure stream Z_MEM_ERROR -> errorWithoutStackTrace "zlib: out of memory"@@ -101,7 +97,7 @@ -- probably more useful for an unsliced version decompress :: Zlib s Chunks decompress = Zlib $ loop ChunksNil- where+ where -- TODO adapt chunkSize based on input remaining and estimated compression ratio chunkSize = 32 * 1024 :: Int loop acc = do@@ -146,41 +142,47 @@ | BufferTooSmall -- corresponds to Z_BUF_ERROR deriving (Show) -instance Exception ZlibError where-+instance Exception ZlibError pattern Z_BUF_ERROR :: CInt pattern Z_BUF_ERROR <- ((== z_BUF_ERROR) -> True)- where Z_BUF_ERROR = z_BUF_ERROR+ where+ Z_BUF_ERROR = z_BUF_ERROR pattern Z_DATA_ERROR :: CInt pattern Z_DATA_ERROR <- ((== z_DATA_ERROR) -> True)- where Z_DATA_ERROR = z_DATA_ERROR+ where+ Z_DATA_ERROR = z_DATA_ERROR pattern Z_MEM_ERROR :: CInt pattern Z_MEM_ERROR <- ((== z_MEM_ERROR) -> True)- where Z_MEM_ERROR = z_MEM_ERROR+ where+ Z_MEM_ERROR = z_MEM_ERROR pattern Z_NEED_DICT :: CInt pattern Z_NEED_DICT <- ((== z_NEED_DICT) -> True)- where Z_NEED_DICT = z_NEED_DICT+ where+ Z_NEED_DICT = z_NEED_DICT pattern Z_OK :: CInt pattern Z_OK <- ((== z_OK) -> True)- where Z_OK = z_OK+ where+ Z_OK = z_OK pattern Z_STREAM_END :: CInt pattern Z_STREAM_END <- ((== z_STREAM_END) -> True)- where Z_STREAM_END = z_STREAM_END+ where+ Z_STREAM_END = z_STREAM_END pattern Z_STREAM_ERROR :: CInt pattern Z_STREAM_ERROR <- ((== z_STREAM_ERROR) -> True)- where Z_STREAM_ERROR = z_STREAM_ERROR+ where+ Z_STREAM_ERROR = z_STREAM_ERROR pattern Z_VERSION_ERROR :: CInt pattern Z_VERSION_ERROR <- ((== z_VERSION_ERROR) -> True)- where Z_VERSION_ERROR = z_VERSION_ERROR-+ where+ Z_VERSION_ERROR = z_VERSION_ERROR ------------ Raw Foreign Imports ------------ @@ -195,22 +197,26 @@ foreign import capi "hs_zlib.h value hs_sizeofStream" sizeofStream :: Int -foreign import ccall unsafe "hs_initDecompress" initDecompress ::- MutableByteArray# s- -> Ptr Word8- -> Int- -> IO CInt+foreign import ccall unsafe "hs_initDecompress"+ initDecompress ::+ MutableByteArray# s ->+ Ptr Word8 ->+ Int ->+ IO CInt -foreign import ccall unsafe "hs_decompressChunk" decompressChunk ::- MutableByteArray# s- -> MutableByteArray# s- -> Int- -> IO CInt+foreign import ccall unsafe "hs_decompressChunk"+ decompressChunk ::+ MutableByteArray# s ->+ MutableByteArray# s ->+ Int ->+ IO CInt -foreign import ccall unsafe "hs_avail_out" availOut ::- MutableByteArray# s- -> IO CInt+foreign import ccall unsafe "hs_avail_out"+ availOut ::+ MutableByteArray# s ->+ IO CInt -foreign import ccall unsafe "inflateEnd" inflateEnd ::- MutableByteArray# s- -> IO CInt+foreign import ccall unsafe "inflateEnd"+ inflateEnd ::+ MutableByteArray# s ->+ IO CInt
test/Main.hs view
@@ -1,22 +1,20 @@-{-# language BangPatterns #-}-{-# language MagicHash #-}+{-# LANGUAGE BangPatterns #-}+{-# LANGUAGE MagicHash #-} -import Zlib (ZlibError(DataCorrupt),decompress)+import Control.Monad (forM_) import Data.Bytes (Bytes) import System.Exit (exitFailure)-import Control.Monad (forM_)+import Zlib (ZlibError (DataCorrupt), decompress) -import qualified Data.Bytes as Bytes-import qualified Data.Bytes.Chunks as Chunks import qualified Data.ByteString as BS import qualified Data.ByteString.Unsafe as BS+import qualified Data.Bytes as Bytes+import qualified Data.Bytes.Chunks as Chunks import qualified Data.List as List import qualified Data.Primitive.ByteArray as BA import qualified Data.Primitive.PrimArray as Prim-import qualified Data.Primitive.Ptr as Prim import qualified GHC.Exts as Exts - main :: IO () main = do forM_ files (uncurry oneTest)@@ -25,14 +23,12 @@ Left DataCorrupt -> pure () Left e -> fail ("unexpected error " ++ show e) Right _ -> fail "garbage data should decompress successfully"- where+ where files = [ ("test/expected-001.txt", "test/input-001.zlib") , ("test/expected-002.txt", "test/input-002.zlib") , ("test/expected-003.bin", "test/input-003.zlib") ]-- oneTest :: FilePath -> FilePath -> IO () oneTest expectedFile inputFile = do
zlib-bytes.cabal view
@@ -1,78 +1,87 @@-cabal-version: 3.0-name: zlib-bytes-version: 0.1.0.1-synopsis: zlib compression bindings-bug-reports: https://github.com/byteverse/zlib-bytes-license: BSD-3-Clause-license-file: LICENSE-author: Eric Demko-maintainer: andrew.thaddeus@gmail.com-copyright: 2020 Andrew Martin-category: Data-build-type: Simple+cabal-version: 3.0+name: zlib-bytes+version: 0.1.0.2+synopsis: zlib compression bindings+description: zlib compression bindings.+homepage: https://github.com/byteverse/zlib-bytes+bug-reports: https://github.com/byteverse/zlib-bytes/issues+license: BSD-3-Clause+license-file: LICENSE+author: Eric Demko+maintainer: amartin@layer3com.com+copyright: 2020 Andrew Martin+category: Data+build-type: Simple extra-source-files:- , CHANGELOG.md- , test/expected-001.txt- , test/expected-002.txt- , test/expected-003.bin- , test/input-001.zlib- , test/input-002.zlib- , test/input-003.zlib- , cbits/trees.h- , cbits/zutil.h- , cbits/inffixed.h- , cbits/zconf.h- , cbits/crc32.h- , cbits/inflate.h- , cbits/zlib.h- , cbits/deflate.h- , cbits/hs_zlib.h- , cbits/inffast.h- , cbits/gzguts.h- , cbits/inftrees.h+ cbits/crc32.h+ cbits/deflate.h+ cbits/gzguts.h+ cbits/hs_zlib.h+ cbits/inffast.h+ cbits/inffixed.h+ cbits/inflate.h+ cbits/inftrees.h+ cbits/trees.h+ cbits/zconf.h+ cbits/zlib.h+ cbits/zutil.h+ test/expected-001.txt+ test/expected-002.txt+ test/expected-003.bin+ test/input-001.zlib+ test/input-002.zlib+ test/input-003.zlib +extra-doc-files: CHANGELOG.md+ library- exposed-modules: Zlib- other-modules: Zlib.Raw+ exposed-modules: Zlib+ other-modules: Zlib.Raw build-depends:- , base >=4.12 && <5- , primitive >=0.7 && <0.10- , byteslice >=0.2.8- , mtl >=2.2- , transformers >=0.6.1+ , base >=4.12 && <5+ , byteslice >=0.2.8+ , mtl >=2.2+ , primitive >=0.7 && <0.10+ , transformers >=0.6.1+ default-language: Haskell2010- ghc-options: -O2 -Wall- include-dirs: cbits+ ghc-options: -O2 -Wall+ include-dirs: cbits c-sources:- , cbits/adler32.c- , cbits/compress.c- , cbits/crc32.c- , cbits/deflate.c- , cbits/gzclose.c- , cbits/gzlib.c- , cbits/gzread.c- , cbits/gzwrite.c- , cbits/hs_zlib.c- , cbits/infback.c- , cbits/inffast.c- , cbits/inflate.c- , cbits/inftrees.c- , cbits/trees.c- , cbits/uncompr.c- , cbits/zutil.c- hs-source-dirs: src+ cbits/adler32.c+ cbits/compress.c+ cbits/crc32.c+ cbits/deflate.c+ cbits/gzclose.c+ cbits/gzlib.c+ cbits/gzread.c+ cbits/gzwrite.c+ cbits/hs_zlib.c+ cbits/infback.c+ cbits/inffast.c+ cbits/inflate.c+ cbits/inftrees.c+ cbits/trees.c+ cbits/uncompr.c+ cbits/zutil.c + hs-source-dirs: src+ test-suite test default-language: Haskell2010- type: exitcode-stdio-1.0- hs-source-dirs: test- main-is: Main.hs- ghc-options: -Wall -O2 -rtsopts "-with-rtsopts=-A64K"+ type: exitcode-stdio-1.0+ hs-source-dirs: test+ main-is: Main.hs+ ghc-options: -Wall -O2 -rtsopts -with-rtsopts=-A64K build-depends:- , base >=4.11.1 && <5+ , base >=4.11.1 && <5 , byteslice- , bytestring >=0.10+ , bytestring >=0.10 , primitive , tasty , tasty-quickcheck , zlib-bytes++source-repository head+ type: git+ location: git://github.com/byteverse/zlib-bytes.git