concurrent-buffer-0.1: Concurrent expanding buffer

Safe HaskellNone




new :: Int -> IO Buffer Source #

Create a new buffer of the specified initial capacity.

push :: Buffer -> Int -> (Ptr Word8 -> IO (Int, result)) -> IO result Source #

Prepares the buffer to be filled with at maximum the specified amount of bytes, then uses the pointer-action to populate it. It is your responsibility to ensure that the action does not exceed the space limit.

The pointer-action returns the amount of bytes it actually writes to the buffer. That amount then is used to move the buffer's cursor accordingly. It can also produce some result, which will then be emitted by push.

It also aligns or grows the buffer if required.

pushBytes :: Buffer -> ByteString -> IO () Source #

Push a byte array into the buffer.

pushStorable :: Storable storable => Buffer -> storable -> IO () Source #

Push a storable value into the buffer.

pull :: Buffer -> Int -> (Ptr Word8 -> IO result) -> IO result Source #

Pulls the specified amount of bytes from the buffer using the provided pointer-action, freeing the buffer from the pulled bytes afterwards.

In case the buffer does not contain enough bytes yet, it will block waiting.

pullBytes :: Buffer -> Int -> IO ByteString Source #

Pulls the specified amount of bytes.

pullStorable :: Storable storable => Buffer -> IO storable Source #

Pulls a storable value.

getSpace :: Buffer -> IO Int Source #

Get how much space is occupied by the buffer's data.

getBytes :: Buffer -> IO ByteString Source #

Create a bytestring representation without modifying the buffer.