HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulebyteslice-0.2.13.2Haskell2010

Data.Bytes.Chunks

Chunks of bytes. This is useful as a target for a builder or as a way to read a large amount of whose size is unknown in advance. Structurally, this type is similar to Data.ByteString.Lazy.ByteString. However, the type in this module is strict in its spine. Additionally, none of the Handle functions perform lazy I/O.

  • 1 type
  • 23 values

Types

1 declaration
datadata Chunks
#

A cons-list of byte sequences.

Instances4Eq, Show, Semigroup, Monoid
  • Eq ChunksDefined in byteslice-0.2.13.2 · Data.Bytes.Chunks

    This uses concat to form an equivalence class.

  • Show ChunksDefined in byteslice-0.2.13.2 · Data.Bytes.Chunks
  • Semigroup ChunksDefined in byteslice-0.2.13.2 · Data.Bytes.Chunks
  • Monoid ChunksDefined in byteslice-0.2.13.2 · Data.Bytes.Chunks

Properties

2 declarations
valuenull :: Chunks -> Bool
#

Are there any bytes in the chunked byte sequences?

Manipulate

10 declarations
valueconcat :: Chunks -> Bytes
#

Concatenate chunks into a single contiguous byte sequence.

valuereplicate
  1. :: Bytes
  2. -> Int

    Number of times to repeat the sequence.

  3. -> Chunks
#

Repeat the byte sequence over and over. Returns empty chunks when given a negative repetition count.

valuereplicateByte
  1. :: Word8
  2. -> Int

    Number of times to replicate the byte

  3. -> Chunks
#

Repeat the byte over and over. This builds a single byte array that is at most 64KiB and shares that across every ChunksCons cell.

An as example, creating a 2GiB chunks this way would use 64KiB for the byte array, and there would be the additional overhead of the 2^15 ChunksCons data constructors. On a 64-bit platform, ChunksCons takes 40 bytes, so the total memory consumption would be 2^16 + 40 * 2^15, which is roughly 1.37MB. The same reasoning shows that it takes about 83.95MB to represent a 128GiB chunks.

The size of the shared payload is an implementation detail. Do not rely on this function producing 64KiB chunks. The implementation might one day change to something smarter that minimizes the memory footprint for very large chunks.

Folds

1 declaration
valuefoldl' :: (a -> Word8 -> a) -> a -> Chunks -> a
#

Left fold over all bytes in the chunks, strict in the accumulator.

Splitting

1 declaration
valuesplit :: Word8 -> Chunks -> [Bytes]
#

Break chunks of bytes into contiguous pieces separated by the byte argument. This is a good producer for list fusion. For this function to perform well, each chunk should contain multiple separators. Any piece that spans multiple chunks must be copied.

Hashing

2 declarations

Create

2 declarations

Copy to buffer

1 declaration
valueunsafeCopy
  1. :: MutableByteArray s

    Destination

  2. -> Int

    Destination offset

  3. -> Chunks

    Source

  4. -> ST s Int

    Returns the next index into the destination after the payload

#

Copy the contents of the chunks into a mutable array. Precondition: The destination must have enough space to house the contents. This is not checked.

I/O with Handles

4 declarations
valuereadFile :: FilePath -> IO Chunks
#

Read an entire file strictly into chunks. If reading from a regular file, this makes an effort read the file into a single chunk.