Safe Haskell | None |
---|---|
Language | Haskell2010 |
Data.Conduit.Binary
Description
NOTE It is recommended to start using Data.Conduit.Combinators instead of this module.
Functions for interacting with bytes.
For many purposes, it's recommended to use the conduit-combinators library, which provides a more complete set of functions.
Synopsis
- sourceFile :: forall (m :: Type -> Type) i. MonadResource m => FilePath -> ConduitT i ByteString m ()
- sourceHandle :: forall (m :: Type -> Type) i. MonadIO m => Handle -> ConduitT i ByteString m ()
- sourceHandleUnsafe :: forall (m :: Type -> Type) i. MonadIO m => Handle -> ConduitT i ByteString m ()
- sourceIOHandle :: forall (m :: Type -> Type) i. MonadResource m => IO Handle -> ConduitT i ByteString m ()
- sourceFileRange :: forall (m :: Type -> Type) i. MonadResource m => FilePath -> Maybe Integer -> Maybe Integer -> ConduitT i ByteString m ()
- sourceHandleRange :: forall (m :: Type -> Type) i. MonadIO m => Handle -> Maybe Integer -> Maybe Integer -> ConduitT i ByteString m ()
- sourceHandleRangeWithBuffer :: forall (m :: Type -> Type) i. MonadIO m => Handle -> Maybe Integer -> Maybe Integer -> Int -> ConduitT i ByteString m ()
- withSourceFile :: forall m (n :: Type -> Type) i a. (MonadUnliftIO m, MonadIO n) => FilePath -> (ConduitM i ByteString n () -> m a) -> m a
- sinkFile :: forall (m :: Type -> Type) o. MonadResource m => FilePath -> ConduitT ByteString o m ()
- sinkFileCautious :: forall (m :: Type -> Type) o. MonadResource m => FilePath -> ConduitM ByteString o m ()
- sinkTempFile :: forall (m :: Type -> Type) o. MonadResource m => FilePath -> String -> ConduitM ByteString o m FilePath
- sinkSystemTempFile :: forall (m :: Type -> Type) o. MonadResource m => String -> ConduitM ByteString o m FilePath
- sinkHandle :: forall (m :: Type -> Type) o. MonadIO m => Handle -> ConduitT ByteString o m ()
- sinkIOHandle :: forall (m :: Type -> Type) o. MonadResource m => IO Handle -> ConduitT ByteString o m ()
- sinkHandleBuilder :: forall (m :: Type -> Type) o. MonadIO m => Handle -> ConduitM Builder o m ()
- sinkHandleFlush :: forall (m :: Type -> Type) o. MonadIO m => Handle -> ConduitM (Flush ByteString) o m ()
- withSinkFile :: forall m (n :: Type -> Type) o a. (MonadUnliftIO m, MonadIO n) => FilePath -> (ConduitM ByteString o n () -> m a) -> m a
- withSinkFileBuilder :: forall m (n :: Type -> Type) o a. (MonadUnliftIO m, MonadIO n) => FilePath -> (ConduitM Builder o n () -> m a) -> m a
- withSinkFileCautious :: forall m (n :: Type -> Type) o a. (MonadUnliftIO m, MonadIO n) => FilePath -> (ConduitM ByteString o n () -> m a) -> m a
- conduitFile :: forall (m :: Type -> Type). MonadResource m => FilePath -> ConduitT ByteString ByteString m ()
- conduitHandle :: forall (m :: Type -> Type). MonadIO m => Handle -> ConduitT ByteString ByteString m ()
- sourceLbs :: forall (m :: Type -> Type) i. Monad m => ByteString -> ConduitT i ByteString m ()
- head :: forall (m :: Type -> Type) o. Monad m => ConduitT ByteString o m (Maybe Word8)
- dropWhile :: forall (m :: Type -> Type) o. Monad m => (Word8 -> Bool) -> ConduitT ByteString o m ()
- take :: forall (m :: Type -> Type) o. Monad m => Int -> ConduitT ByteString o m ByteString
- drop :: forall (m :: Type -> Type) o. Monad m => Int -> ConduitT ByteString o m ()
- sinkCacheLength :: forall (m1 :: Type -> Type) (m2 :: Type -> Type) o i. (MonadResource m1, MonadResource m2) => ConduitT ByteString o m1 (Word64, ConduitT i ByteString m2 ())
- sinkLbs :: forall (m :: Type -> Type) o. Monad m => ConduitT ByteString o m ByteString
- mapM_ :: Monad m => (Word8 -> m ()) -> ConduitT ByteString o m ()
- sinkStorable :: forall (m :: Type -> Type) a o. (Monad m, Storable a) => ConduitT ByteString o m (Maybe a)
- sinkStorableEx :: forall (m :: Type -> Type) a o. (MonadThrow m, Storable a) => ConduitT ByteString o m a
- isolate :: forall (m :: Type -> Type). Monad m => Int -> ConduitT ByteString ByteString m ()
- takeWhile :: forall (m :: Type -> Type). Monad m => (Word8 -> Bool) -> ConduitT ByteString ByteString m ()
- lines :: forall (m :: Type -> Type). Monad m => ConduitT ByteString ByteString m ()
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 :: forall (m :: Type -> Type) i. MonadResource m => FilePath -> ConduitT i ByteString m () #
sourceHandle :: forall (m :: Type -> Type) i. MonadIO m => Handle -> ConduitT i ByteString m () #
sourceHandleUnsafe :: forall (m :: Type -> Type) i. MonadIO m => Handle -> ConduitT i ByteString m () #
sourceIOHandle :: forall (m :: Type -> Type) i. MonadResource m => IO Handle -> ConduitT i ByteString m () #
Arguments
:: forall (m :: Type -> Type) i. MonadResource m | |
=> FilePath | |
-> Maybe Integer | Offset |
-> Maybe Integer | Maximum count |
-> ConduitT i ByteString m () |
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
Arguments
:: forall (m :: Type -> Type) i. MonadIO m | |
=> Handle | |
-> Maybe Integer | Offset |
-> Maybe Integer | Maximum count |
-> ConduitT i ByteString m () |
Stream the contents of a handle as binary data, starting from a certain offset and only consuming up to a certain number of bytes.
Since 1.0.8
sourceHandleRangeWithBuffer Source #
Arguments
:: forall (m :: Type -> Type) i. MonadIO m | |
=> Handle | |
-> Maybe Integer | Offset |
-> Maybe Integer | Maximum count |
-> Int | Buffer size |
-> ConduitT i ByteString m () |
Stream the contents of a handle as binary data, starting from a certain offset and only consuming up to a certain number of bytes. This function consumes chunks as specified by the buffer size.
Since 1.1.8
withSourceFile :: forall m (n :: Type -> Type) i a. (MonadUnliftIO m, MonadIO n) => FilePath -> (ConduitM i ByteString n () -> m a) -> m a #
Sinks
sinkFile :: forall (m :: Type -> Type) o. MonadResource m => FilePath -> ConduitT ByteString o m () #
sinkFileCautious :: forall (m :: Type -> Type) o. MonadResource m => FilePath -> ConduitM ByteString o m () #
sinkTempFile :: forall (m :: Type -> Type) o. MonadResource m => FilePath -> String -> ConduitM ByteString o m FilePath #
sinkSystemTempFile :: forall (m :: Type -> Type) o. MonadResource m => String -> ConduitM ByteString o m FilePath #
sinkHandle :: forall (m :: Type -> Type) o. MonadIO m => Handle -> ConduitT ByteString o m () #
sinkIOHandle :: forall (m :: Type -> Type) o. MonadResource m => IO Handle -> ConduitT ByteString o m () #
sinkHandleBuilder :: forall (m :: Type -> Type) o. MonadIO m => Handle -> ConduitM Builder o m () #
sinkHandleFlush :: forall (m :: Type -> Type) o. MonadIO m => Handle -> ConduitM (Flush ByteString) o m () #
withSinkFile :: forall m (n :: Type -> Type) o a. (MonadUnliftIO m, MonadIO n) => FilePath -> (ConduitM ByteString o n () -> m a) -> m a #
withSinkFileBuilder :: forall m (n :: Type -> Type) o a. (MonadUnliftIO m, MonadIO n) => FilePath -> (ConduitM Builder o n () -> m a) -> m a #
withSinkFileCautious :: forall m (n :: Type -> Type) o a. (MonadUnliftIO m, MonadIO n) => FilePath -> (ConduitM ByteString o n () -> m a) -> m a #
Conduits
conduitFile :: forall (m :: Type -> Type). MonadResource m => FilePath -> ConduitT ByteString ByteString m () Source #
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
conduitHandle :: forall (m :: Type -> Type). MonadIO m => Handle -> ConduitT ByteString ByteString m () Source #
Stream the contents of the input to a Handle
, and also send it along the
pipeline. Similar in concept to the Unix command tee
. Like sourceHandle
,
does not close the handle on completion. Related to: conduitFile
.
Since 1.0.9
Utilities
Sources
sourceLbs :: forall (m :: Type -> Type) i. Monad m => ByteString -> ConduitT i ByteString m () Source #
Stream the chunks from a lazy bytestring.
Since 0.5.0
Sinks
head :: forall (m :: Type -> Type) o. Monad m => ConduitT ByteString o m (Maybe Word8) Source #
Return the next byte from the stream, if available.
Since 0.3.0
dropWhile :: forall (m :: Type -> Type) o. Monad m => (Word8 -> Bool) -> ConduitT ByteString o m () Source #
Ignore all bytes while the predicate returns True
.
Since 0.3.0
take :: forall (m :: Type -> Type) o. Monad m => Int -> ConduitT ByteString o m ByteString Source #
Take the given number of bytes, if available.
Since 0.3.0
drop :: forall (m :: Type -> Type) o. Monad m => Int -> ConduitT ByteString o m () Source #
Drop up to the given number of bytes.
Since 0.5.0
sinkCacheLength :: forall (m1 :: Type -> Type) (m2 :: Type -> Type) o i. (MonadResource m1, MonadResource m2) => ConduitT ByteString o m1 (Word64, ConduitT i ByteString m2 ()) Source #
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
sinkLbs :: forall (m :: Type -> Type) o. Monad m => ConduitT ByteString o m ByteString Source #
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
mapM_ :: Monad m => (Word8 -> m ()) -> ConduitT ByteString o m () Source #
Perform a computation on each Word8
in a stream.
Since 1.0.10
Storable
sinkStorable :: forall (m :: Type -> Type) a o. (Monad m, Storable a) => ConduitT ByteString o m (Maybe a) Source #
Consume some instance of Storable
from the incoming byte stream. In the
event of insufficient bytes in the stream, returns a Nothing
and returns
all unused input as leftovers.
Since: 1.1.13
sinkStorableEx :: forall (m :: Type -> Type) a o. (MonadThrow m, Storable a) => ConduitT ByteString o m a Source #
Same as sinkStorable
, but throws a SinkStorableInsufficientBytes
exception (via throwM
) in the event of insufficient bytes. This can be
more efficient to use than sinkStorable
as it avoids the need to
construct/deconstruct a Maybe
wrapper in the success case.
Since: 1.1.13
Conduits
isolate :: forall (m :: Type -> Type). Monad m => Int -> ConduitT ByteString ByteString m () Source #
Ensure that only up to the given number of bytes are consumed by the inner sink. Note that this does not ensure that all of those bytes are in fact consumed.
Since 0.3.0