streaming-bytestring-0.1.0.6: effectful byte steams, or: lazy bytestring done right

Safe HaskellNone
LanguageHaskell2010

Data.ByteString.Streaming.Internal

Synopsis

Documentation

data ByteString m r Source

A space-efficient representation of a succession of Word8 vectors, supporting many efficient operations.

An effectful ByteString contains 8-bit bytes, or by using the operations from Data.ByteString.Streaming.Char8 it can be interpreted as containing 8-bit characters.

Constructors

Empty r 
Chunk !ByteString (ByteString m r) 
Go (m (ByteString m r)) 

consChunk :: ByteString -> ByteString m r -> ByteString m r Source

Smart constructor for Chunk.

chunkOverhead :: Int Source

The memory management overhead. Currently this is tuned for GHC only.

defaultChunkSize :: Int Source

The chunk size used for I/O. Currently set to 32k, less the memory management overhead

materialize :: (forall x. (r -> x) -> (ByteString -> x -> x) -> (m x -> x) -> x) -> ByteString m r Source

Construct a succession of chunks from its Church encoding (compare GHC.Exts.build)

dematerialize :: Monad m => ByteString m r -> forall x. (r -> x) -> (ByteString -> x -> x) -> (m x -> x) -> x Source

Resolve a succession of chunks into its Church encoding; this is not a safe operation; it is equivalent to exposing the constructors

foldrChunks :: Monad m => (ByteString -> a -> a) -> a -> ByteString m r -> m a Source

Consume the chunks of an effectful ByteString with a natural right fold.

foldlChunks :: Monad m => (a -> ByteString -> a) -> a -> ByteString m r -> m (Of a r) Source

foldrChunksM :: Monad m => (ByteString -> m a -> m a) -> m a -> ByteString m r -> m a Source

Consume the chunks of an effectful ByteString with a natural right monadic fold.

foldlChunksM :: Monad m => (a -> ByteString -> m a) -> m a -> ByteString m r -> m (Of a r) Source

unfoldMChunks :: Monad m => (s -> m (Maybe (ByteString, s))) -> s -> ByteString m () Source

unfoldrChunks :: Monad m => (s -> m (Either r (ByteString, s))) -> s -> ByteString m r Source

smallChunkSize :: Int Source

The recommended chunk size. Currently set to 4k, less the memory management overhead

packBytes :: Monad m => Stream (Of Word8) m r -> ByteString m r Source

Packing and unpacking from lists packBytes' :: Monad m => [Word8] -> ByteString m () packBytes' cs0 = packChunks 32 cs0 where packChunks n cs = case S.packUptoLenBytes n cs of (bs, []) -> Chunk bs (Empty ()) (bs, cs') -> Chunk bs (packChunks (min (n * 2) BI.smallChunkSize) cs') -- packUptoLenBytes :: Int -> [Word8] -> (ByteString, [Word8]) packUptoLenBytes len xs0 = unsafeDupablePerformIO (createUptoN' len $ p -> go p len xs0) where go !_ !n [] = return (len-n, []) go !_ !0 xs = return (len, xs) go !p !n (x:xs) = poke p x >> go (p plusPtr 1) (n-1) xs createUptoN' :: Int -> (Ptr Word8 -> IO (Int, a)) -> IO (S.ByteString, a) createUptoN' l f = do fp <- S.mallocByteString l (l', res) withForeignPtr fp $ p - f p assert (l' <= l) $ return (S.PS fp 0 l', res) {--}

chunk :: ByteString -> ByteString m () Source

Yield-style smart constructor for Chunk.

wrap :: m (ByteString m r) -> ByteString m r Source

Smart constructor for Go.

unfoldrNE :: Int -> (a -> Either r (Word8, a)) -> a -> (ByteString, Either r a) Source

reread :: Monad m => (s -> m (Maybe ByteString)) -> s -> ByteString m () Source