Bytes unstable
Joins and compares byte sequences stored in Uint8Array values.
Byte-to-text conversions live in TextEncoder / TextDecoder, and hex or
base64 conversions live in the Encoding modules.
Combinators
Joins byte chunks into one new Uint8Array.
When to use
Use to combine frames, headers, or streamed chunks into a single buffer.
Gotchas
The result is always a new array, even when there is zero or one chunk, so it never aliases an input.
Signature
declare function concat(chunks: readonly Array<Uint8Array<ArrayBufferLike>>): Uint8Array<ArrayBuffer>Example Joining byte chunks
import { Bytes } from "effect"
const bytes = Bytes.concat([new Uint8Array([1, 2]), new Uint8Array([3])])Array.from(bytes) // => [1, 2, 3]Instances
Equivalence
unstable Since v4.0.6 Source
Compares byte sequences for equality, byte by byte.
Gotchas
This returns as soon as a byte differs, so it is not constant-time. Do not use it to compare secrets.
Signature
declare const Equivalence: Equ.Equivalence<Uint8Array>Example Comparing byte sequences
import { Bytes } from "effect"
Bytes.Equivalence(new Uint8Array([1, 2]), new Uint8Array([1, 2])) // => trueBytes.Equivalence(new Uint8Array([1, 2]), new Uint8Array([1])) // => falseOrders byte sequences lexicographically by unsigned byte value, placing a prefix before any longer sequence that starts with it.
Signature
declare const Order: order.Order<Uint8Array>Example Sorting byte sequences
import { Bytes } from "effect"
Bytes.Order(new Uint8Array([1, 2]), new Uint8Array([1, 3])) // => -1Bytes.Order(new Uint8Array([2]), new Uint8Array([1, 9])) // => 1Bytes.Order(new Uint8Array([1]), new Uint8Array([1, 0])) // => -1