packages feed

conduit 1.0.4.2 → 1.0.5

raw patch · 3 files changed

+55/−4 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Data.Conduit.Binary: sinkCacheLength :: (MonadResource m1, MonadResource m2) => Sink ByteString m1 (Word64, Source m2 ByteString)
+ Data.Conduit.Binary: sinkLbs :: Monad m => Sink ByteString m ByteString

Files

Data/Conduit/Binary.hs view
@@ -26,6 +26,8 @@     , dropWhile     , take     , drop+    , sinkCacheLength+    , sinkLbs       -- ** Conduits     , isolate     , takeWhile@@ -36,13 +38,15 @@ import qualified Data.ByteString as S import qualified Data.ByteString.Lazy as L import Data.Conduit-import Data.Conduit.List (sourceList)-import Control.Exception (assert)+import Data.Conduit.List (sourceList, consume)+import Control.Exception (assert, finally) import Control.Monad (unless) import Control.Monad.IO.Class (liftIO, MonadIO)+import Control.Monad.Trans.Resource (allocate, release) import qualified System.IO as IO-import Data.Word (Word8)+import Data.Word (Word8, Word64) import Control.Applicative ((<$>))+import System.Directory (getTemporaryDirectory, removeFile) #if CABAL_OS_WINDOWS import qualified System.Win32File as F #elif NO_HANDLES@@ -319,3 +323,39 @@ -- Since 0.5.0 sourceLbs :: Monad m => L.ByteString -> Producer m S.ByteString sourceLbs = sourceList . L.toChunks++-- | Stream the input data into a temp file and count the number of bytes+-- present. When complete, return a new @Source@ reading from the temp file+-- together with the length of the input in bytes.+--+-- All resources will be cleaned up automatically.+--+-- Since 1.0.5+sinkCacheLength :: (MonadResource m1, MonadResource m2)+                => Sink S.ByteString m1 (Word64, Source m2 S.ByteString)+sinkCacheLength = do+    tmpdir <- liftIO getTemporaryDirectory+    (releaseKey, (fp, h)) <- allocate+        (IO.openBinaryTempFile tmpdir "conduit.cache")+        (\(fp, h) -> IO.hClose h `finally` removeFile fp)+    len <- sinkHandleLen h+    liftIO $ IO.hClose h+    return (len, sourceFile fp >> release releaseKey)+  where+    sinkHandleLen :: MonadResource m => IO.Handle -> Sink S.ByteString m Word64+    sinkHandleLen h =+        loop 0+      where+        loop x =+            await >>= maybe (return x) go+          where+            go bs = do+                liftIO $ S.hPut h bs+                loop $ x + fromIntegral (S.length bs)++-- | Consume a stream of input into a lazy bytestring. Note that no lazy I\/O+-- is performed, but rather all content is read into memory strictly.+--+-- Since 1.0.5+sinkLbs :: Monad m => Sink S.ByteString m L.ByteString+sinkLbs = fmap L.fromChunks consume
conduit.cabal view
@@ -1,5 +1,5 @@ Name:                conduit-Version:             1.0.4.2+Version:             1.0.5 Synopsis:            Streaming data processing library. Description:     @conduit@ is a solution to the streaming data problem, allowing for production, transformation, and consumption of streams of data in constant memory. It is an alternative to lazy I\/O which guarantees deterministic resource handling, and fits in the same general solution space as @enumerator@\/@iteratee@ and @pipes@. For a tutorial, please visit <https://haskell.fpcomplete.com/user/snoyberg/library-documentation/conduit-overview>.@@ -58,6 +58,7 @@                      , text                     >= 0.11                      , void                     >= 0.5.5                      , mmorph+                     , directory   ghc-options:     -Wall  test-suite test
test/main.hs view
@@ -874,5 +874,15 @@             res <- C.yield 10 C.$$ C.awaitForever (C.toProducer . src) C.=$ (C.toConsumer sink >>= C.yield) C.=$ C.await             res `shouldBe` Just (sum [1..10]) +    describe "sinkCacheLength" $ do+        it' "works" $ C.runResourceT $ do+            lbs <- liftIO $ L.readFile "test/main.hs"+            (len, src) <- CB.sourceLbs lbs C.$$ CB.sinkCacheLength+            lbs' <- src C.$$ CB.sinkLbs+            liftIO $ do+                fromIntegral len `shouldBe` L.length lbs+                lbs' `shouldBe` lbs+                fromIntegral len `shouldBe` L.length lbs'+ it' :: String -> IO () -> Spec it' = it