diff --git a/src/Data/Binary/Get.hs b/src/Data/Binary/Get.hs index 62207594..f62dc618 100644 --- a/src/Data/Binary/Get.hs +++ b/src/Data/Binary/Get.hs @@ -145,6 +145,7 @@ module Data.Binary.Get ( -- $incrementalinterface , Decoder(..) , runGetIncremental + , runGetIncremental' -- ** Providing input , pushChunk @@ -228,7 +229,7 @@ import qualified Data.ByteString.Unsafe as B import qualified Data.ByteString.Lazy as L import qualified Data.ByteString.Lazy.Internal as L -import Data.Binary.Get.Internal hiding ( Decoder(..), runGetIncremental ) +import Data.Binary.Get.Internal hiding ( Decoder(..), runGetIncremental, runGetIncremental') import qualified Data.Binary.Get.Internal as I #if defined(__GLASGOW_HASKELL__) && !defined(__HADDOCK__) @@ -284,6 +285,11 @@ data Decoder a = Fail !B.ByteString {-# UNPACK #-} !ByteOffset String runGetIncremental :: Get a -> Decoder a runGetIncremental = calculateOffset . I.runGetIncremental +-- | Similar to 'runGetIncremental', but accept an initial chunk, it's faster +-- than feeding initial chunk after 'runGetIncremental'. +runGetIncremental' :: Get a -> B.ByteString -> Decoder a +runGetIncremental' g = calculateOffset . I.runGetIncremental' g + calculateOffset :: I.Decoder a -> Decoder a calculateOffset r0 = go r0 0 where diff --git a/src/Data/Binary/Get/Internal.hs b/src/Data/Binary/Get/Internal.hs index c2ebcffa..4391fe9a 100644 --- a/src/Data/Binary/Get/Internal.hs +++ b/src/Data/Binary/Get/Internal.hs @@ -11,6 +11,7 @@ module Data.Binary.Get.Internal ( , runCont , Decoder(..) , runGetIncremental + , runGetIncremental' , readN , readNWith @@ -145,8 +146,12 @@ instance (Show a) => Show (Decoder a) where -- | Run a 'Get' monad. See 'Decoder' for what to do next, like providing -- input, handling decoding errors and to get the output value. runGetIncremental :: Get a -> Decoder a -runGetIncremental g = noMeansNo $ - runCont g B.empty (\i a -> Done i a) +runGetIncremental g = noMeansNo $ runCont g B.empty Done + +-- | Similar to 'runGetIncremental', but accept an initial chunk, it's faster +-- than feeding initial chunk after 'runGetIncremental'. +runGetIncremental' :: Get a -> B.ByteString -> Decoder a +runGetIncremental' g bs = noMeansNo $ runCont g bs Done -- | Make sure we don't have to pass Nothing to a Partial twice. -- This way we don't need to pass around an EOF value in the Get monad, it