lz4-hs 0.1.0.0 → 0.1.1.0
raw patch · 6 files changed
+48/−7 lines, 6 files
Files
- CHANGELOG.md +7/−0
- README.md +1/−1
- lz4-hs.cabal +2/−2
- src/Codec/Lz4.hs +22/−2
- src/Codec/Lz4/Foreign.chs +13/−0
- test/Spec.hs +3/−2
CHANGELOG.md view
@@ -1,5 +1,12 @@ # lz4 +## 0.1.1.0++ * Export `lZ4VersionString` and `lZ4VersionNumber`+ * Add `lZ4MaxInputSize` and `lZ4HCClevelMax`+ * Add `compressBlockHC`+ * Add `{-# NOINLINE -#}` pragmas in various places+ ## 0.1.0.0 Initial release
README.md view
@@ -9,4 +9,4 @@ [lz4](https://hackage.haskell.org/package/lz4) and [lz4-conduit](https://hackage.haskell.org/package/lz4-conduit). -This mean you can work with `.lz4` files.+This means you can work with `.lz4` files.
lz4-hs.cabal view
@@ -1,6 +1,6 @@ cabal-version: 1.18 name: lz4-hs-version: 0.1.0.0+version: 0.1.1.0 license: BSD3 license-file: LICENSE copyright: Copyright: (c) 2020 Vanessa McHale@@ -36,7 +36,7 @@ ghc-options: -Wall build-depends:- base >=4.3 && <5,+ base >=4.8 && <5, bytestring -any if impl(ghc >=8.0)
src/Codec/Lz4.hs view
@@ -4,9 +4,15 @@ module Codec.Lz4 ( -- * Functions for working with blocks compressBlock , decompressBlockSz+ , lZ4MaxInputSize+ , compressBlockHC+ , lZ4HCClevelMax -- * Functions for working with frames , compress , decompress+ -- * Version info+ , lZ4VersionNumber+ , lZ4VersionString ) where import Codec.Lz4.Foreign@@ -18,6 +24,8 @@ import qualified Data.ByteString.Internal as BS import qualified Data.ByteString.Lazy as BSL import qualified Data.ByteString.Unsafe as BS+import Foreign.C.String (CString)+import Foreign.C.Types (CInt) import Foreign.ForeignPtr (ForeignPtr, castForeignPtr, mallocForeignPtrBytes, newForeignPtr, withForeignPtr)@@ -117,16 +125,28 @@ check res BS.packCStringLen (d, fromIntegral res) +{-# NOINLINE compressBlock #-} compressBlock :: BS.ByteString -> BS.ByteString-compressBlock bs = unsafePerformIO $+compressBlock = unsafePerformIO . compressBlockGeneric lZ4CompressDefault++{-# NOINLINE compressBlockHC #-}+-- | @since 0.1.1.0+compressBlockHC :: Int -- ^ Compression level (must be less than 'lZ4HCClevelMax')+ -> BS.ByteString+ -> BS.ByteString+compressBlockHC lvl = unsafePerformIO . compressBlockGeneric (\src dst ssz dsz -> lZ4CompressHC src dst ssz dsz (fromIntegral lvl))++compressBlockGeneric :: (CString -> CString -> CInt -> CInt -> IO CInt) -> BS.ByteString -> IO BS.ByteString+compressBlockGeneric cfun bs = BS.unsafeUseAsCStringLen bs $ \(buf, sz) -> do let resSz = lZ4CompressBound (fromIntegral sz) dst <- mallocForeignPtrBytes (fromIntegral resSz) withForeignPtr dst $ \d -> do- bWritten <- lZ4CompressDefault buf d (fromIntegral sz) resSz+ bWritten <- cfun buf d (fromIntegral sz) resSz when (bWritten == 0) $ error "Compression error" BS.packCStringLen (d, fromIntegral bWritten) +{-# NOINLINE decompressBlockSz #-} -- | Decompress a block. The size of the uncompressed data must be known. decompressBlockSz :: BS.ByteString -> Int -- ^ Decompressed size
src/Codec/Lz4/Foreign.chs view
@@ -18,6 +18,9 @@ , lZ4FCreateDecompressionContext , lZ4FFreeDecompressionContext , lZ4FDecompress+ , lZ4MaxInputSize+ , lZ4CompressHC+ , lZ4HCClevelMax -- * Types , LZ4FErrorCode , LzCtx@@ -34,6 +37,7 @@ #include <lz4.h> #include <lz4frame.h>+#include <lz4hc.h> {# fun pure LZ4_versionNumber as ^ {} -> `CInt' #} {# fun pure LZ4_versionString as ^ {} -> `String' #}@@ -104,3 +108,12 @@ , `LzDecompressOptionsPtr' } -> `CULong' #}++lZ4MaxInputSize :: Integral a => a+lZ4MaxInputSize = {# const LZ4_MAX_INPUT_SIZE #}++{# fun LZ4_compress_HC as ^ + { `CString', `CString', `CInt', `CInt', `CInt' } -> `CInt' #}++lZ4HCClevelMax :: Integral a => a+lZ4HCClevelMax = {# const LZ4HC_CLEVEL_MAX #}
test/Spec.hs view
@@ -20,7 +20,7 @@ actual @?= contents main :: IO ()-main = do+main = defaultMain $ testGroup "lz4" [testBlocks, testFrames]@@ -31,4 +31,5 @@ , testRoundtripBlocks "LICENSE" ] testFrames = testGroup "Frame compression"- [ testRoundtripFrames "cbits/lz4.c" ]+ [ testRoundtripFrames "cbits/lz4.c"+ ]