packages feed

bz3 0.1.0.1 → 1.0.0.0

raw patch · 4 files changed

+24/−10 lines, 4 filesdep +randomPVP ok

version bump matches the API change (PVP)

Dependencies added: random

API changes (from Hackage documentation)

+ Codec.Bz3: compressFileDefault :: ByteString -> ByteString
- Codec.Bz3: compressFile :: ByteString -> ByteString
+ Codec.Bz3: compressFile :: Int32 -> ByteString -> ByteString

Files

CHANGELOG.md view
@@ -1,3 +1,8 @@+# 1.0.0.0++  * `compressFile` now takes block size+  * Add `compressFileDefault`+ # 0.1.0.1  * Fix bug compressing files that are not large
bz3.cabal view
@@ -1,6 +1,6 @@ cabal-version:      3.4 name:               bz3-version:            0.1.0.1+version:            1.0.0.0 synopsis:           High-level bindings to bz3 description:     Streaming compression/decompression in bz3 format via lazy bytestrings@@ -22,7 +22,7 @@  common warnings     ghc-options:-        -Wall -fno-warn-missing-signatures -Wno-x-partial+        -Wall -fno-warn-missing-signatures         -Wincomplete-uni-patterns -Wincomplete-record-updates         -Wredundant-constraints -Wmissing-export-lists -Wcpp-undef         -Wunused-packages -Wno-operator-whitespace-ext-conflict@@ -56,5 +56,6 @@         bz3,         bytestring,         directory >=1.2.5.0,+        random >=1.0.0,         tasty,         tasty-hunit
src/Codec/Bz3.hs view
@@ -1,6 +1,7 @@ module Codec.Bz3 ( Bz3Error (..)                  , decompressFile                  , compressFile+                 , compressFileDefault                  ) where  import           Codec.Bz3.Binary@@ -33,9 +34,14 @@     loop st bs | BSL.null bs = pure []                | otherwise = do {(dc, rest) <- decN st bs; (dc:) <$> loop st rest} +-- | @since 1.0.0.0+compressFileDefault :: BSL.ByteString -> BSL.ByteString+compressFileDefault = compressFile (16*1024*1024)+ -- will fail if bz3st cannot fit exotic big input-compressFile :: BSL.ByteString -> BSL.ByteString-compressFile d = LazyST.runST $ do+compressFile :: Int32 -- ^ Block size, 65kB to 511MB+             -> BSL.ByteString -> BSL.ByteString+compressFile ibSz d = LazyST.runST $ do     st <- LazyST.unsafeIOToST $ newBz3StForeign bSz     (sz,bb) <- loop st (BSL.toChunks d)     let fileH = runPut (putFileH sz)@@ -53,7 +59,7 @@     feed=fromIntegral (bz3Bound bSz)      bSz :: Integral a => a-    bSz=16*1024*1024+    bSz=fromIntegral ibSz  encN :: ForeignPtr Bz3St -> BS.ByteString -> LazyST.ST s (Int32, BS.ByteString) encN st inp = LazyST.unsafeIOToST $@@ -68,12 +74,12 @@ decN :: ForeignPtr Bz3St -> BSL.ByteString -> LazyST.ST s (BS.ByteString, BSL.ByteString) decN st inp = LazyST.unsafeIOToST $ do     let (next, off, Chunk csz osz) = y (runGetOrFail getChunk inp)+        bb=BSL.toStrict (BSL.drop 8 $ BSL.take off inp)     if osz>=64         then do             let bufSz = bz3Bound (fromIntegral osz)                 csz32 = fromIntegral csz; osz32 = fromIntegral osz             buf <- mallocForeignPtrBytes (fromIntegral bufSz)-            let bb=BSL.toStrict (BSL.drop 8 $ BSL.take off inp)             res <- withForeignPtr buf $ \b -> do                 BS.unsafeUseAsCStringLen bb $ \(p,isz) -> copyArray b (castPtr p) isz                 bz3DecodeBlock st b bufSz csz32 osz32@@ -82,7 +88,6 @@                 Left e | e==Bz3Ok -> pure ()                        | otherwise -> error =<< bz3Strerror st             pure (BS.BS (castForeignPtr buf) (fromIntegral osz), next)-        else let bb=BSL.toStrict (BSL.drop 8 $ BSL.take off inp)-             in pure (bb, next)+        else pure (bb, next)   where     y (Right x) = x; y (Left (_, _, e)) = error e
test/Main.hs view
@@ -3,6 +3,7 @@ import           Codec.Bz3 import qualified Data.ByteString.Lazy as BSL import           System.Directory     (doesDirectoryExist, listDirectory)+import           System.Random        (randomRIO) import           Test.Tasty           (defaultMain, testGroup) import           Test.Tasty.HUnit     (assertBool, testCase) @@ -13,7 +14,9 @@  roundtrip fp = testCase ("roundtrip " ++ fp) $ do     contents <- BSL.readFile fp-    let d = decompressFile contents-        e = compressFile d+    eb <- randomRIO (2::Int,8)+    let bsz=2^eb*1024*1024+        d = decompressFile contents+        e = compressFile bsz d         d1 = decompressFile e     assertBool "doesn't error" (d1 `seq` True)