conduit-extra-1.3.6: Batteries included conduit: adapters for common libraries.

Safe Haskell | Safe-Inferred
Language | Haskell2010

Data.Conduit.ByteString.Builder

Contents

- Conduits from builders to bytestrings
  - Flush
- Buffer allocation strategies

Description

Convert a stream of blaze-builder `Builder`s into a stream of `ByteString`s.

Works with both blaze-builder < 0.4's `Builder`s and `Builder`.

Adapted from blaze-builder-enumerator, written by myself and Simon Meier.

Note that the functions here can work in any monad built on top of `IO` or `ST`.

Since 1.1.7.0

Synopsis

- builderToByteString :: forall (m :: Type -> Type). PrimMonad m => ConduitT Builder ByteString m ()
- unsafeBuilderToByteString :: forall (m :: Type -> Type). PrimMonad m => ConduitT Builder ByteString m ()
- builderToByteStringWith :: forall (m :: Type -> Type). PrimMonad m => BufferAllocStrategy -> ConduitT Builder ByteString m ()
- builderToByteStringFlush :: forall (m :: Type -> Type). PrimMonad m => ConduitT (Flush Builder) (Flush ByteString) m ()
- builderToByteStringWithFlush :: forall (m :: Type -> Type). PrimMonad m => BufferAllocStrategy -> ConduitT (Flush Builder) (Flush ByteString) m ()
- type BufferAllocStrategy = (IO Buffer, Int -> Buffer -> IO (IO Buffer))
- allNewBuffersStrategy :: Int -> BufferAllocStrategy
- reuseBufferStrategy :: IO Buffer -> BufferAllocStrategy

# Conduits from builders to bytestrings

builderToByteString :: forall (m :: Type -> Type). PrimMonad m => ConduitT Builder ByteString m () #

Incrementally execute builders and pass on the filled chunks as bytestrings.

Since: conduit-1.3.0

unsafeBuilderToByteString :: forall (m :: Type -> Type). PrimMonad m => ConduitT Builder ByteString m () #

Incrementally execute builders on the given buffer and pass on the filled chunks as bytestrings. Note that, if the given buffer is too small for the execution of a build step, a larger one will be allocated.

WARNING: This conduit yields bytestrings that are NOT referentially transparent. Their content will be overwritten as soon as control is returned from the inner sink!

Since: conduit-1.3.0

builderToByteStringWith :: forall (m :: Type -> Type). PrimMonad m => BufferAllocStrategy -> ConduitT Builder ByteString m () #

A conduit that incrementally executes builders and passes on the filled chunks as bytestrings to an inner sink.

INV: All bytestrings passed to the inner sink are non-empty.

Since: conduit-1.3.0

## Flush

builderToByteStringFlush :: forall (m :: Type -> Type). PrimMonad m => ConduitT (Flush Builder) (Flush ByteString) m () #

Same as `builderToByteString`, but input and output are wrapped in `Flush`.

Since: conduit-1.3.0

builderToByteStringWithFlush :: forall (m :: Type -> Type). PrimMonad m => BufferAllocStrategy -> ConduitT (Flush Builder) (Flush ByteString) m () #

Since: conduit-1.3.0

# Buffer allocation strategies

type BufferAllocStrategy = (IO Buffer, Int -> Buffer -> IO (IO Buffer)) #

A buffer allocation strategy `(buf0, nextBuf)` specifies the initial buffer to use and how to compute a new buffer `nextBuf minSize buf` with at least size `minSize` from a filled buffer `buf`. The double nesting of the `IO` monad helps to ensure that the reference to the filled buffer `buf` is lost as soon as possible, but the new buffer doesn't have to be allocated too early.

Since: conduit-1.3.0

allNewBuffersStrategy :: Int -> BufferAllocStrategy #

The simplest buffer allocation strategy: whenever a buffer is requested, allocate a new one that is big enough for the next build step to execute.

NOTE that this allocation strategy may spill quite some memory upon direct insertion of a bytestring by the builder. Thats no problem for garbage collection, but it may lead to unreasonably high memory consumption in special circumstances.

Since: conduit-1.3.0

reuseBufferStrategy :: IO Buffer -> BufferAllocStrategy #

An unsafe, but possibly more efficient buffer allocation strategy: reuse the buffer, if it is big enough for the next build step to execute.

Since: conduit-1.3.0