byteslice-0.2.2.0: Slicing managed and unmanaged memory

Safe HaskellNone
LanguageHaskell2010

Data.Bytes.Chunks

Contents

Description

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.

Synopsis

Types

data Chunks Source #

A cons-list of byte sequences.

Constructors

ChunksCons !Bytes !Chunks 
ChunksNil 
Instances
Eq Chunks Source #

This uses concat to form an equivalence class.

Instance details

Defined in Data.Bytes.Chunks

Methods

(==) :: Chunks -> Chunks -> Bool #

(/=) :: Chunks -> Chunks -> Bool #

Show Chunks Source # 
Instance details

Defined in Data.Bytes.Chunks

Semigroup Chunks Source # 
Instance details

Defined in Data.Bytes.Chunks

Monoid Chunks Source # 
Instance details

Defined in Data.Bytes.Chunks

Properties

length :: Chunks -> Int Source #

The total number of bytes in all the chunks.

Manipulate

concat :: Chunks -> Bytes Source #

Concatenate chunks into a single contiguous byte sequence.

concatPinned :: Chunks -> Bytes Source #

Variant of concat that ensure that the resulting byte sequence is pinned memory.

concatU :: Chunks -> ByteArray Source #

Variant of concat that returns an unsliced byte sequence.

reverse :: Chunks -> Chunks Source #

Reverse chunks but not the bytes within each chunk.

reverseOnto :: Chunks -> Chunks -> Chunks Source #

Variant of reverse that allows the caller to provide an initial list of chunks that the reversed chunks will be pushed onto.

Create

fromBytes :: Bytes -> Chunks Source #

Create a list of chunks with a single chunk.

fromByteArray :: ByteArray -> Chunks Source #

Variant of fromBytes where the single chunk is unsliced.

Copy to buffer

unsafeCopy Source #

Arguments

:: MutableByteArray s

Destination

-> Int

Destination offset

-> Chunks

Source

-> 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

hGetContents :: Handle -> IO Chunks Source #

Read a handle's entire contents strictly into chunks.