HORIZON HASKELLDocslts/ghc-9.14.xb2f3bfd2026-10-11Search names, modules, packages, or :: a typeCtrl K

GHC 9.14.1 · lts/ghc-9.14.x · b2f3bfd · 2026-10-11

Moduleram-0.22.1Haskell2010

Data.ByteArray

Simple and efficient byte array types

This module should be imported qualified.

  • 4 types
  • 2 classes
  • 37 values
  • Packageram-0.22.1
  • Exports43
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceByteArray.hs

ByteArray Classes

2 declarations
classclass ByteArrayAccess ba where
#

Class to Access size properties and data of a ByteArray

Methods

Instances6ByteArrayAccess

ByteArray built-in types

7 declarations
datadata Bytes
#

Simplest Byte Array

Instances8Eq, Ord, Show, Semigroup, Monoid, NFData, …
datadata ScrubbedBytes
#

ScrubbedBytes is a memory chunk which have the properties of:

  • Being scrubbed after its goes out of scope.

  • A Show instance that doesn't actually show any content

  • A Eq instance that is constant time

Instances9Eq, Ord, Show, IsString, Semigroup, Monoid, …
datadata MemView
#

A simple abstraction to a piece of memory.

Do beware that garbage collection related to piece of memory could be triggered before this is used.

Only use with the appropriate handler has been used (e.g. withForeignPtr on ForeignPtr)

Constructors

Instances3Eq, Show, ByteArrayAccess
valuedropView
  1. :: ByteArrayAccess bytes
  2. => bytes

    byte array

  3. -> Int

    the number of bytes do dropped before creating the view

  4. -> View bytes
#

create a view from the given byte array starting after having dropped the fist n bytes

valueview
  1. :: ByteArrayAccess bytes
  2. => bytes

    the byte array we put a view on

  3. -> Int

    the offset to start the byte array on

  4. -> Int

    the size of the view

  5. -> View bytes
#

create a view on a given bytearray

This function update the offset and the size in order to guarantee:

  • offset >= 0

  • size >= 0

  • offset < length

  • size =< length - offset

ByteArray methods

34 declarations
valuealloc :: ByteArray ba => Int -> (Ptr p -> IO ()) -> IO ba
#

Allocate a new bytearray of specific size, and run the initializer on this memory

valueappend :: ByteArray bs => bs -> bs -> bs
#

append one bytearray to the other

valueconstEq :: (ByteArrayAccess bs1, ByteArrayAccess bs2) => bs1 -> bs2 -> Bool
#

A constant time equality test for 2 ByteArrayAccess values.

If values are of 2 different sizes, the function will abort early without comparing any bytes.

compared to == , this function will go over all the bytes present before yielding a result even when knowing the overall result early in the processing.

valuecreate :: ByteArray ba => Int -> (Ptr p -> IO ()) -> IO ba
#

Allocate a new bytearray of specific size, and run the initializer on this memory

valuedrop :: ByteArray bs => Int -> bs -> bs
#

drop the first n byte of a bytearray

valueeq :: (ByteArrayAccess bs1, ByteArrayAccess bs2) => bs1 -> bs2 -> Bool
#

Check if two bytearray are equals

This is not constant time, as soon some byte differs the function will returns. use constEq in sensitive context where timing matters.

valueindex :: ByteArrayAccess a => a -> Int -> Word8
#

return a specific byte indexed by a number from 0 in a bytearray

unsafe, no bound checking are done

valueslice :: ByteArray bs => bs -> Int -> Int -> Maybe bs
#

Extract len bytes starting at byte offset. Returns Nothing if offset or len is negative, or if offset + len exceeds the byte array length.

valuespan :: ByteArray bs => (Word8 -> Bool) -> bs -> (bs, bs)
#

Split a bytearray at the point where pred becomes invalid

valuesplitAt :: ByteArray bs => Int -> bs -> (bs, bs)
#

Split a bytearray at a specific length in two bytearray

valuetake :: ByteArray bs => Int -> bs -> bs
#

Take the first n byte of a bytearray

valueuncons :: ByteArray a => a -> Maybe (Word8, a)
#

returns the first byte, and the remaining bytearray if the bytearray is not null

valueunsafeSlice :: ByteArray bs => bs -> Int -> Int -> bs
#

Like slice but calls error when arguments are out of bounds. This includes negative offset, negative len, or offset + len exceeding the byte array length.

valuezero :: ByteArray ba => Int -> ba
#

Create a bytearray of a specific size initialized to 0