HORIZON HASKELLDocslts/ghc-10.0.x2b276322026-10-31Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 2b27632 · 2026-10-31

Moduleram-0.22.1Haskell2010

Data.ByteArray

Simple and efficient byte array types

This module should be imported qualified.

Contents
  1. ByteArray Classes
  2. ByteArray built-in types
  3. ByteArray methods
Synopsis
  • Packageram-0.22.1
  • Exports43
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceByteArray.hs

ByteArray Classes

classclass ByteArrayAccess ba where

Class to Access size properties and data of a ByteArray

Methods

Instances6ByteArrayAccess

ByteArray built-in types

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

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

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

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.

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.

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.

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.