byteslice-0.2.11.1: Slicing managed and unmanaged memory
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.Bytes.Chunks

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

Instances details
Monoid Chunks Source # 
Instance details

Defined in Data.Bytes.Chunks

Semigroup Chunks Source # 
Instance details

Defined in Data.Bytes.Chunks

Show Chunks Source # 
Instance details

Defined in Data.Bytes.Chunks

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 #

Properties

length :: Chunks -> Int Source #

The total number of bytes in all the chunks.

null :: Chunks -> Bool Source #

Are there any bytes in the chunked byte sequences?

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.

concatPinnedU :: Chunks -> ByteArray Source #

Variant of concatPinned that returns an unsliced pinned byte sequence.

concatByteString :: Chunks -> ByteString Source #

Concatenate chunks into a strict bytestring.

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.

Folds

foldl' :: (a -> Word8 -> a) -> a -> Chunks -> a Source #

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

Splitting

split :: Word8 -> Chunks -> [Bytes] Source #

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

fnv1a32 :: Chunks -> Word32 Source #

Hash byte sequence with 32-bit variant of FNV-1a.

fnv1a64 :: Chunks -> Word64 Source #

Hash byte sequence with 64-bit variant of FNV-1a.

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.

readFile :: FilePath -> IO Chunks Source #

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

hPut :: Handle -> Chunks -> IO () Source #

Outputs Chunks to the specified Handle. This is implemented with hPut.

writeFile :: FilePath -> Chunks -> IO () Source #

Write Chunks to a file, replacing the previous contents of the file.