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 -> IntGet the length of a mutable byte string in bytes; pure, as a buffer cannot be resized after allocation.
#unsafeIndex Source
unsafeIndex :: forall h. STByteString h -> Int -> ST h ByteRead the byte at the given index, throwing an exception if the index is
out of range. Use index for safe access.
#fill Source
fill :: forall h. STByteString h -> Byte -> ST h UnitFill the entire byte string with the given byte value.
#copyInto Source
copyInto :: forall h. { count :: Int, dest :: STByteString h, destOffset :: Int, src :: STByteString h, srcOffset :: Int } -> ST h UnitCopy 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)) -> ByteStringSafely build an immutable byte string with a mutable computation.
#freeze Source
freeze :: forall h. STByteString h -> ST h ByteStringCreate 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.