pipes-binary 0.4.0.5 → 0.4.1
raw patch · 4 files changed
+43/−6 lines, 4 filesdep ~binarydep ~transformersPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependency ranges changed: binary, transformers
API changes (from Hackage documentation)
- Pipes.Binary: deConsumed :: DecodingError -> {-# UNPACK #-} !ByteOffset
- Pipes.Binary: deMessage :: DecodingError -> !String
- Pipes.Binary: instance Constructor C1_0DecodingError
- Pipes.Binary: instance Data DecodingError
- Pipes.Binary: instance Datatype D1DecodingError
- Pipes.Binary: instance Eq DecodingError
- Pipes.Binary: instance Error DecodingError
- Pipes.Binary: instance Exception DecodingError
- Pipes.Binary: instance Generic DecodingError
- Pipes.Binary: instance Read DecodingError
- Pipes.Binary: instance Selector S1_0_0DecodingError
- Pipes.Binary: instance Selector S1_0_1DecodingError
- Pipes.Binary: instance Show DecodingError
- Pipes.Binary: instance Typeable DecodingError
+ Pipes.Binary: [deConsumed] :: DecodingError -> {-# UNPACK #-} !ByteOffset
+ Pipes.Binary: [deMessage] :: DecodingError -> !String
+ Pipes.Binary: instance Control.Monad.Trans.Error.Error Pipes.Binary.DecodingError
+ Pipes.Binary: instance Data.Data.Data Pipes.Binary.DecodingError
+ Pipes.Binary: instance GHC.Classes.Eq Pipes.Binary.DecodingError
+ Pipes.Binary: instance GHC.Exception.Exception Pipes.Binary.DecodingError
+ Pipes.Binary: instance GHC.Generics.Constructor Pipes.Binary.C1_0DecodingError
+ Pipes.Binary: instance GHC.Generics.Datatype Pipes.Binary.D1DecodingError
+ Pipes.Binary: instance GHC.Generics.Generic Pipes.Binary.DecodingError
+ Pipes.Binary: instance GHC.Generics.Selector Pipes.Binary.S1_0_0DecodingError
+ Pipes.Binary: instance GHC.Generics.Selector Pipes.Binary.S1_0_1DecodingError
+ Pipes.Binary: instance GHC.Read.Read Pipes.Binary.DecodingError
+ Pipes.Binary: instance GHC.Show.Show Pipes.Binary.DecodingError
- Pipes.Binary: decodeGet :: Monad m => Get a -> Parser ByteString m (Either DecodingError a)
+ Pipes.Binary: decodeGet :: (Monad m) => Get a -> Parser ByteString m (Either DecodingError a)
- Pipes.Binary: decodeGetL :: Monad m => Get a -> Parser ByteString m (Either DecodingError (ByteOffset, a))
+ Pipes.Binary: decodeGetL :: (Monad m) => Get a -> Parser ByteString m (Either DecodingError (ByteOffset, a))
- Pipes.Binary: encodePut :: Monad m => Put -> Producer' ByteString m ()
+ Pipes.Binary: encodePut :: (Monad m) => Put -> Producer' ByteString m ()
Files
- changelog.md +7/−0
- pipes-binary.cabal +3/−3
- src/Pipes/Binary.hs +21/−3
- tests/Main.hs +12/−0
changelog.md view
@@ -1,3 +1,10 @@+# Version 0.4.1++* Fix #24 - skip leading empty chunks when decoding.++* Upper bound dependency bumps (transformers, binary).++ # Version 0.4.0.5 * Upper bound dependency bumps (tasty).
pipes-binary.cabal view
@@ -1,5 +1,5 @@ name: pipes-binary-version: 0.4.0.5+version: 0.4.1 license: BSD3 license-file: LICENSE copyright: Copyright (c) Renzo Carbonara 2013-2014@@ -29,13 +29,13 @@ ghc-options: -Wall -O2 build-depends: base >= 4.5 && < 5- , binary >= 0.6 && < 0.8+ , binary >= 0.6 && < 0.9 , bytestring >= 0.9.2.1 , ghc-prim , pipes >= 4.0 && < 4.2 , pipes-parse >= 3.0 && < 3.1 , pipes-bytestring >= 2.0 && < 2.2- , transformers >= 0.2 && < 0.5+ , transformers >= 0.2 && < 0.6 test-suite tests type: exitcode-stdio-1.0
src/Pipes/Binary.hs view
@@ -55,6 +55,7 @@ import Data.Binary.Put (Put) import qualified Data.Binary.Put as Put import Data.ByteString (ByteString)+import qualified Data.ByteString as BS import Data.Data (Data, Typeable) import GHC.Generics (Generic) import Pipes@@ -123,7 +124,7 @@ decoded k p = fmap _encode (k (_decode p)) where _decode p0 = do- x <- lift (next p0)+ x <- lift (nextSkipEmpty p0) case x of Left r -> return (Right r) Right (bs, p1) -> do@@ -158,7 +159,7 @@ decodedL k p = fmap _encode (k (_decode p)) where _decode p0 = do- x <- lift (next p0)+ x <- lift (nextSkipEmpty p0) case x of Left r -> return (Right r) Right (bs, p1) -> do@@ -196,7 +197,7 @@ Get.Fail _ off str -> return (Left (DecodingError off str), diffP p0) Get.Done bs off a -> return (Right (off, a), yield bs >> p0) Get.Partial k -> do- x <- next p0+ x <- nextSkipEmpty p0 case x of Left e -> go diffP (k Nothing) (return e) Right (bs, p1) -> go (diffP . (yield bs >>)) (k (Just bs)) p1@@ -215,6 +216,23 @@ instance Exception DecodingError instance Error DecodingError +--------------------------------------------------------------------------------+-- Internal stuff++-- | Like 'Pipes.next', except it skips leading 'BS.null' chunks.+nextSkipEmpty+ :: Monad m+ => Producer ByteString m r+ -> m (Either r (ByteString, Producer ByteString m r))+nextSkipEmpty = go where+ go p0 = do+ x <- next p0+ case x of+ Left _ -> return x+ Right (a,p1)+ | BS.null a -> go p1+ | otherwise -> return x+{-# INLINABLE nextSkipEmpty #-} --------------------------------------------------------------------------------
tests/Main.hs view
@@ -8,6 +8,7 @@ import Test.Tasty.SmallCheck (forAll, testProperty) +import Control.Exception (throwIO) import Control.Monad import Control.Monad.Trans.Maybe import Control.Monad.Trans.State.Strict (StateT, evalStateT,@@ -17,6 +18,7 @@ import qualified Data.ByteString.Lazy as BL import Data.Functor.Identity (runIdentity) import Data.Maybe+import Lens.Family (view) import Lens.Family.State.Strict (zoom) import Pipes import qualified Pipes.Binary as PBin@@ -115,4 +117,14 @@ guard $ xrest == xrest' p0 = for (each xs) PBin.encode in isJust $ runIdentity $ evalStateT (runMaybeT dec0) p0+ , testCase "Decoding an empty stream shouldn't fail" (do+ let p :: Monad m+ => Producer Int m+ (Either (PBin.DecodingError, Producer B.ByteString m ()) ())+ p = view PBin.decoded (yield B.empty)++ x <- runEffect (p >-> P.print)+ case x of+ Left (err, _) -> throwIO err+ Right r -> return r ) ]