ChunkedBuffer #
This module provides an efficient way to concatenate multiple ByteArrays by deferring the actual
concatenation until necessary. This is particularly useful in HTTP response building and streaming
scenarios where data is accumulated incrementally.
A structure that accumulates multiple ByteArrays efficiently by tracking them in an array and
maintaining the total size. This allows building large buffers without repeated allocations and copies.
The accumulated byte arrays.
The accumulated byte arrays.
- size : Nat
The total size in bytes of all accumulated arrays
- size : Nat
The total size in bytes of all accumulated arrays
Instances For
Writes a ByteArray to the ChunkedBuffer.
Instances For
Writes a Char to the ChunkedBuffer. Only the low byte is written (Char.toUInt8),
so this is only correct for ASCII characters.
Instances For
Writes a String to the ChunkedBuffer.
Equations
- buffer.writeString data = buffer.push data.toUTF8
Instances For
Turn the combined structure into a single contiguous ByteArray.
Equations
- cb.toByteArray = if h : 1 = cb.data.size then cb.data[0] else Array.foldl (fun (x1 x2 : ByteArray) => x1 ++ x2) (ByteArray.emptyWithCapacity cb.size) cb.data
Instances For
Build from a ByteArray directly.
Instances For
Build from an array of ByteArrays directly.
Equations
- Std.Http.Internal.ChunkedBuffer.ofArray bs = { data := bs, size := Array.foldl (fun (x1 : Nat) (x2 : ByteArray) => x1 + x2.size) 0 bs }
Instances For
Checks whether the buffer is empty.
Instances For
Equations
Equations
- Std.Http.Internal.ChunkedBuffer.instEmptyCollection = { emptyCollection := Std.Http.Internal.ChunkedBuffer.empty }