packages feed

streaming-bytestring 0.1.0.2 → 0.1.0.3

raw patch · 3 files changed

+42/−8 lines, 3 files

Files

Data/ByteString/Streaming.hs view
@@ -100,7 +100,8 @@     , splitWith        -- splitWith :: Monad m => (Word8 -> Bool) -> ByteString m r -> Stream (ByteString m) m r      , take             -- take :: Monad m => GHC.Int.Int64 -> ByteString m r -> ByteString m ()      , takeWhile        -- takeWhile :: (Word8 -> Bool) -> ByteString m r -> ByteString m () -+    , denull+         -- ** Breaking into many substrings     , split            -- split :: Monad m => Word8 -> ByteString m r -> Stream (ByteString m) m r      @@ -493,7 +494,9 @@ nextChunk :: Monad m => ByteString m r -> m (Either r (S.ByteString, ByteString m r)) nextChunk = \bs -> case bs of   Empty r    -> return (Left r)-  Chunk c cs -> return (Right (c,cs))+  Chunk c cs -> if S.null c +    then nextChunk cs+    else return (Right (c,cs))   Go m       -> m >>= nextChunk {-# INLINABLE nextChunk #-} @@ -1522,3 +1525,32 @@       Delay mls -> Delay $ liftM (loop a) mls  {-#INLINABLE zipWithStream #-}++{- Remove empty bytestrings from a stream of connected bytestrings,+   as with Prelude @filter (not . null)@  This does not block streaming.++>>> let humpty = "all the\n\nking\'s horses"+>>> Q.putStrLn humpty+all the++king's horses+>>> Q.putStrLn $ Q.unlines $ Q.denull $ Q.lines humpty+all the+king's horses ++>>> putStrLn $ unlines $ filter (not.null) $ lines humpty+all the+king's horses++-}+denull :: Monad m => Stream (ByteString m) m r -> Stream (ByteString m) m r+denull = loop where+  loop stream = do+    e <- lift $ inspect stream+    case e of+      Left r         -> Return r+      Right bsstream ->  do+         e <- lift $ nextChunk bsstream+         case e of +           Left stream -> loop stream+           Right (bs, qbs) -> Step (chunk bs >> fmap loop qbs)
Data/ByteString/Streaming/Char8.hs view
@@ -77,7 +77,7 @@     , words     , linesIndividual     , wordsIndividual-    +    , denull     -- ** Special folds      , concat          -- concat :: Monad m => Stream (ByteString m) m r -> ByteString m r @@ -161,7 +161,7 @@     fromChunks, toChunks, fromStrict, toStrict, toStrict',      concat, distribute, drain,     empty, null, null', length, length', append, cycle, -    take, drop, splitAt, intercalate, group,+    take, drop, splitAt, intercalate, group, denull,     appendFile, stdout, stdin, fromHandle, toHandle,     hGetContents, hGetContentsN, hGet, hGetN, hPut,      getContents, hGetNonBlocking,
streaming-bytestring.cabal view
@@ -1,6 +1,6 @@ name:                streaming-bytestring-version:             0.1.0.2-synopsis:            effectful bytestrings, or: lazy bytestring done right+version:             0.1.0.3+synopsis:            effectful byte steams, or: lazy bytestring done right description:         This is an implementation of effectful, memory-constrained                       bytestrings (byte streams) and functions for streaming                       bytestring manipulation, adequate for non-lazy-io. @@ -15,15 +15,17 @@                      > IOStreams.unfoldM Streaming.unconsChunk :: ByteString IO () -> IO (InputStream ByteString)                      > Streaming.reread IOStreams.read         :: InputStream ByteString -> ByteString IO ()                      .-                     and similarly for other streaming io libraries. +                     and similarly for other rational streaming io libraries.                       .                      A tutorial module is in the works;                       <https://gist.github.com/michaelt/6c6843e6dd8030e95d58 here> -                     is a sequence of simplified implementations of familiar shell utilities. +                     is a sequence of simplified implementations of familiar shell utilities.                        It closely follows those at the end of the                      <http://hackage.haskell.org/package/io-streams-1.3.2.0/docs/System-IO-Streams-Tutorial.html io-streams tutorial>.                      It is generally much simpler; in some case simpler than what                      you would write with lazy bytestrings. +                     <https://gist.github.com/michaelt/2dcea1ba32562c091357 Here>+                     is a simple GET request that returns a byte stream.                      .                      The implementation follows the                      details of @Data.ByteString.Lazy@ and @Data.ByteString.Lazy.Char8@