Module

Data.ByteString.ST

Package
purescript-bytestrings
Repository
f-f/purescript-bytestrings

This module defines a type of mutable byte strings in the ST monad, and associated helper functions. For a long-lived buffer in Effect, use the Global region with Control.Monad.ST.Global.toEffect.

#STByteString Source

data STByteString :: Region -> Typedata STByteString t0

A reference to a mutable byte string.

The type parameter represents the memory region which the byte string belongs to. The runtime representation of an STByteString h is the same as that of a ByteString, except that mutation is allowed.

#create Source

create :: forall h. Int -> ST h (STByteString h)

Create a mutable byte string of the given length, filled with zeros.

#createWith Source

createWith :: forall h. Int -> Byte -> ST h (STByteString h)

Create a mutable byte string of the given length, filled with the given byte value.

#length Source

length :: forall h. STByteString h -> Int

Get the length of a mutable byte string in bytes; pure, as a buffer cannot be resized after allocation.

#index Source

index :: forall h. STByteString h -> Int -> ST h (Maybe Byte)

Read the byte at the given index, returning Nothing if the index is out of range.

#unsafeIndex Source

unsafeIndex :: forall h. STByteString h -> Int -> ST h Byte

Read the byte at the given index, throwing an exception if the index is out of range. Use index for safe access.

#set Source

set :: forall h. STByteString h -> Int -> Byte -> ST h Unit

Set the byte at the given index, throwing an exception if the index is out of range.

#fill Source

fill :: forall h. STByteString h -> Byte -> ST h Unit

Fill the entire byte string with the given byte value.

#map Source

map :: forall h. STByteString h -> (Byte -> Byte) -> ST h Unit

Transform every byte in place with the given function.

#copyInto Source

copyInto :: forall h. { count :: Int, dest :: STByteString h, destOffset :: Int, src :: STByteString h, srcOffset :: Int } -> ST h Unit

Copy count bytes from src (at srcOffset) into dest (at destOffset), throwing an exception if either range is out of bounds. dest and src may be the same buffer and the ranges may overlap: the destination always receives the bytes the source range held before the copy began.

#copy Source

copy :: forall h. STByteString h -> ST h (STByteString h)

Allocate an independent copy of a mutable byte string.

#run Source

run :: (forall h. ST h (STByteString h)) -> ByteString

Safely build an immutable byte string with a mutable computation.

#freeze Source

freeze :: forall h. STByteString h -> ST h ByteString

Create an immutable copy of a mutable byte string; mutating the source afterwards does not affect the result.

#thaw Source

thaw :: forall h. ByteString -> ST h (STByteString h)

Create a mutable copy of an immutable byte string; mutating the result does not affect the source.