quicklz 1.5.0.4 → 1.5.0.5
raw patch · 5 files changed
+42/−6 lines, 5 filesPVP: minor bump suggested
API additions: PVP suggests at least a minor version bump
API changes (from Hackage documentation)
+ Codec.Compression.QuickLZ: decompress' :: ByteString -> ByteString
Files
- Codec/Compression/QuickLZ.hsc +16/−1
- README +0/−3
- README.md +19/−0
- quicklz.cabal +2/−2
- tests/Properties.hs +5/−0
Codec/Compression/QuickLZ.hsc view
@@ -1,5 +1,4 @@ {-# LANGUAGE CPP, ForeignFunctionInterface #-} - -- | -- Module : Codec.Compression.QuickLZ -- Copyright : (c) Austin Seipp 2011 @@ -40,6 +39,7 @@ ( -- * Compressing and decompressing strict 'ByteString's compress -- :: S.ByteString -> S.ByteString , decompress -- :: S.ByteString -> S.ByteString +, decompress' -- :: S.ByteString -> S.ByteString ) where import Foreign @@ -80,6 +80,21 @@ c_ <- c_qlz_decompress cstr output decompress_state return $ c_ - 4 -- hack: remove 4 ending bytes off of output string {-# INLINEABLE decompress #-} + +-- | Decompress the input 'ByteString' and save memory via overlapping decompression. +decompress' :: S.ByteString -> S.ByteString +decompress' xs + | S.null xs = S.empty + | otherwise = + unsafePerformIO . allocaBytes qlz_state_decompress_sz $ \decompress_state -> do + d <- U.unsafeUseAsCString xs c_qlz_size_decompressed + let sz = (d + (d `shiftR` 3) + 400) + SI.createAndTrim sz $ \output -> do + U.unsafeUseAsCStringLen xs $ \(cstr,clen) -> do + let dest = output `plusPtr` (sz - clen) + SI.memcpy dest (castPtr cstr) (fromIntegral clen) + c_ <- c_qlz_decompress dest output decompress_state + return $ c_ - 4 -- hack: remove 4 ending bytes off of output string -- -- Simple bindings to some constants
− README
@@ -1,3 +0,0 @@-hs-quicklz: haskell bindings to quicklz - -TODO
+ README.md view
@@ -0,0 +1,19 @@+# hs-quicklz: haskell bindings to quicklz + +This library implements haskell bindings to [QuickLZ](http://quicklz.com), a fast +compression library. The interface is very simple: + + compress :: ByteString -> ByteString + decompress :: ByteString -> ByteString + decompress' :: ByteString -> ByteString -- overlapping decompression + +As the name states, QuickLZ is fast - very fast at both compression and decompression. +Per its own benchmarks, at compression level 1, QuickLZ 1.5.0 has a compression speed +of 308Mbyte/s, and a decompression speed of 358Mbyte/s (their benchmarks, Core i7 920.) +This package has some benchmarks and tests associated - I would like to expand the benchmarks +to include bigger data sets in the future. + +There is currently only an interface for strict bytestrings. + +I would like to implement the streaming mode functionality sometime in the future, perhaps +tying it to John Millikin's [enumerator](http://hackage.haskell.org/package/enumerator) package.
quicklz.cabal view
@@ -1,5 +1,5 @@ name: quicklz -version: 1.5.0.4 +version: 1.5.0.5 synopsis: binding to QuickLZ compression library description: This package provides a high level binding to the QuickLZ (<http://quicklz.com>) library @@ -25,7 +25,7 @@ extra-source-files: cbits/quicklz.h, cbits/quicklz.c, tests/ex1.hs, tests/Properties.hs, - README + README.md source-repository head type: git
tests/Properties.hs view
@@ -12,6 +12,7 @@ testProperty "compression identity" prop_compression_id , testProperty "decompress is pure" prop_decompress_pure , testProperty "compress is pure" prop_compress_pure + , testProperty "overlapping is correct" prop_overlap_id ] ] @@ -24,3 +25,7 @@ prop_compress_pure (S.pack -> xs) = (compress xs) == (compress xs) + +prop_overlap_id (S.pack -> xs) = + let z = compress xs + in (decompress z) == (decompress' z)