pipes-bytestring-1.0.2: ByteString support for pipes

Safe HaskellNone

Pipes.ByteString.Parse

Contents

Description

Parsing utilities for bytestrings, in the style of pipes-parse

Synopsis

Parsers

nextByte :: Monad m => Producer BS.ByteString m r -> m (Either r (Word8, Producer BS.ByteString m r))Source

Consume the first byte from a byte stream

next either fails with a Left if the Producer has no more bytes or succeeds with a Right providing the next byte and the remainder of the Producer.

drawByte :: Monad m => StateT (Producer BS.ByteString m r) m (Either r Word8)Source

Draw one Word8 from the underlying Producer, returning Left if the Producer is empty

unDrawByte :: Monad m => Word8 -> StateT (Producer BS.ByteString m r) m ()Source

Push back a Word8 onto the underlying Producer

peekByte :: Monad m => StateT (Producer BS.ByteString m r) m (Either r Word8)Source

peekByte checks the first Word8 in the stream, but uses unDrawByte to push the Word8 back

 peekByte = do
     x <- drawByte
     case x of
         Left  _  -> return ()
         Right w8 -> unDrawByte w8
     return x

isEndOfBytes :: Monad m => StateT (Producer BS.ByteString m r) m BoolSource

Check if the underlying Producer has no more bytes

Note that this will skip over empty BS.ByteString chunks, unlike PP.isEndOfInput from pipes-parse.

 isEndOfBytes = liftM isLeft peekByte

take :: (Monad m, Integral a) => a -> Pipe BS.ByteString BS.ByteString (StateT (Producer BS.ByteString m r) m) ()Source

(take n) only allows n bytes to pass

Unlike Pipes.ByteString.take, this PP.unDraws unused bytes

takeWhile :: Monad m => (Word8 -> Bool) -> Pipe BS.ByteString BS.ByteString (StateT (Producer BS.ByteString m r) m) ()Source

Take bytes until they fail the predicate

Unlike Pipes.ByteString.takeWhile, this PP.unDraws unused bytes