Safe Haskell | None |
---|
Functions for interacting with bytes.
- sourceFile :: MonadResource m => FilePath -> GSource m ByteString
- sourceHandle :: MonadIO m => Handle -> GSource m ByteString
- sourceIOHandle :: MonadResource m => IO Handle -> GSource m ByteString
- sourceFileRange :: MonadResource m => FilePath -> Maybe Integer -> Maybe Integer -> GSource m ByteString
- sinkFile :: MonadResource m => FilePath -> GInfSink ByteString m
- sinkHandle :: MonadIO m => Handle -> GInfSink ByteString m
- sinkIOHandle :: MonadResource m => IO Handle -> GInfSink ByteString m
- conduitFile :: MonadResource m => FilePath -> GInfConduit ByteString m ByteString
- sourceLbs :: Monad m => ByteString -> GSource m ByteString
- head :: Monad m => GLSink ByteString m (Maybe Word8)
- dropWhile :: Monad m => (Word8 -> Bool) -> GLSink ByteString m ()
- take :: Monad m => Int -> GLSink ByteString m ByteString
- drop :: Monad m => Int -> GLSink ByteString m ()
- isolate :: Monad m => Int -> GLConduit ByteString m ByteString
- takeWhile :: Monad m => (Word8 -> Bool) -> GLConduit ByteString m ByteString
- lines :: Monad m => GInfConduit ByteString m ByteString
Files and Handle
s
Note that most of these functions live in the MonadResource
monad
to ensure resource finalization even in the presence of exceptions. In
order to run such code, you will need to use runResourceT
.
Sources
sourceFile :: MonadResource m => FilePath -> GSource m ByteStringSource
Stream the contents of a file as binary data.
Since 0.3.0
sourceHandle :: MonadIO m => Handle -> GSource m ByteStringSource
Stream the contents of a Handle
as binary data. Note that this
function will not automatically close the Handle
when processing
completes, since it did not acquire the Handle
in the first place.
Since 0.3.0
sourceIOHandle :: MonadResource m => IO Handle -> GSource m ByteStringSource
An alternative to sourceHandle
.
Instead of taking a pre-opened Handle
, it takes an action that opens
a Handle
(in read mode), so that it can open it only when needed
and closed it as soon as possible.
Since 0.3.0
:: MonadResource m | |
=> FilePath | |
-> Maybe Integer | Offset |
-> Maybe Integer | Maximum count |
-> GSource m ByteString |
Stream the contents of a file as binary data, starting from a certain offset and only consuming up to a certain number of bytes.
Since 0.3.0
Sinks
sinkFile :: MonadResource m => FilePath -> GInfSink ByteString mSource
Stream all incoming data to the given file.
Since 0.3.0
sinkHandle :: MonadIO m => Handle -> GInfSink ByteString mSource
Stream all incoming data to the given Handle
. Note that this function
will not automatically close the Handle
when processing completes.
Since 0.3.0
sinkIOHandle :: MonadResource m => IO Handle -> GInfSink ByteString mSource
An alternative to sinkHandle
.
Instead of taking a pre-opened Handle
, it takes an action that opens
a Handle
(in write mode), so that it can open it only when needed
and close it as soon as possible.
Since 0.3.0
Conduits
conduitFile :: MonadResource m => FilePath -> GInfConduit ByteString m ByteStringSource
Stream the contents of the input to a file, and also send it along the
pipeline. Similar in concept to the Unix command tee
.
Since 0.3.0
Utilities
Sources
sourceLbs :: Monad m => ByteString -> GSource m ByteStringSource
Stream the chunks from a lazy bytestring.
Since 0.5.0
Sinks
head :: Monad m => GLSink ByteString m (Maybe Word8)Source
Return the next byte from the stream, if available.
Since 0.3.0
dropWhile :: Monad m => (Word8 -> Bool) -> GLSink ByteString m ()Source
Ignore all bytes while the predicate returns True
.
Since 0.3.0
take :: Monad m => Int -> GLSink ByteString m ByteStringSource
Take the given number of bytes, if available.
Since 0.3.0
drop :: Monad m => Int -> GLSink ByteString m ()Source
Drop up to the given number of bytes.
Since 0.5.0
Conduits
isolate :: Monad m => Int -> GLConduit ByteString m ByteStringSource
Ensure that only up to the given number of bytes are consume by the inner sink. Note that this does not ensure that all of those bytes are in fact consumed.
Since 0.3.0
takeWhile :: Monad m => (Word8 -> Bool) -> GLConduit ByteString m ByteStringSource
Return all bytes while the predicate returns True
.
Since 0.3.0
lines :: Monad m => GInfConduit ByteString m ByteStringSource
Split the input bytes into lines. In other words, split on the LF byte (10), and strip it from the output.
Since 0.3.0