streaming-commons-0.1.9.1: Common lower-level functions needed by various streaming data libraries

Safe Haskell | None
Language | Haskell98

Data.Streaming.ByteString.Builder

Description

Provides `toByteStringIO*` like Blaze.ByteString.Builders, for Data.ByteString.Builder.

Since 0.1.9

Synopsis

- toByteStringIO :: (ByteString -> IO ()) -> Builder -> IO ()
- toByteStringIOWith :: Int -> (ByteString -> IO ()) -> Builder -> IO ()
- toByteStringIOWithBuffer :: Int -> (ByteString -> IO ()) -> Builder -> ForeignPtr Word8 -> IO ()

# Documentation

toByteStringIO :: (ByteString -> IO ()) -> Builder -> IO ()

Run the builder with a `defaultChunkSize`d buffer and execute the given `IO` action whenever the buffer is full or gets flushed.

     toByteStringIO = toByteStringIOWith defaultChunkSize

Since 0.1.9

toByteStringIOWith

Arguments

:: Int | Buffer size (upper bounds the number of bytes forced per call to the `IO` action).
-> (ByteString -> IO ()) | `IO` action to execute per full buffer, which is referenced by a strict `ByteString`.
-> Builder | `Builder` to run.
-> IO () |

`toByteStringIOWith bufSize io b` runs the builder `b` with a buffer of at least the size `bufSize` and executes the `IO` action `io` whenever the buffer is full.

Compared to `toLazyByteStringWith` this function requires less allocation, as the output buffer is only allocated once at the start of the serialization and whenever something bigger than the current buffer size has to be copied into the buffer, which should happen very seldomly for the default buffer size of 32kb. Hence, the pressure on the garbage collector is reduced, which can be an advantage when building long sequences of bytes.

Since 0.1.9

toByteStringIOWithBuffer :: Int -> (ByteString -> IO ()) -> Builder -> ForeignPtr Word8 -> IO ()

Use a pre-existing buffer to `toByteStringIOWith`.

Since 0.1.9