gossamer/uint8_array
Types
A typed array of 8-bit unsigned integers (bytes).
See Uint8Array on MDN.
pub type Uint8Array
Values
pub fn at(
array: Uint8Array,
index index: Int,
) -> Result(Int, Nil)
Returns the byte at index, or Error(Nil) if the index is out of
bounds. Negative indices count from the end.
pub fn buffer(of array: Uint8Array) -> array_buffer.ArrayBuffer
pub fn byte_length(of array: Uint8Array) -> Int
pub fn byte_offset(of array: Uint8Array) -> Int
pub fn copy_within(
array: Uint8Array,
to target: Int,
from start: Int,
) -> Uint8Array
pub fn copy_within_range(
array: Uint8Array,
to target: Int,
from start: Int,
up_to end: Int,
) -> Uint8Array
pub fn entries(
of array: Uint8Array,
) -> iterator.Iterator(#(Int, Int), Nil, Nil)
pub fn every(
in array: Uint8Array,
satisfying predicate: fn(Int) -> Bool,
) -> Bool
pub fn fill(array: Uint8Array, with value: Int) -> Uint8Array
pub fn fill_range(
array: Uint8Array,
with value: Int,
from start: Int,
to end: Int,
) -> Uint8Array
pub fn filter(
in array: Uint8Array,
keeping predicate: fn(Int) -> Bool,
) -> Uint8Array
pub fn find(
in array: Uint8Array,
one_that predicate: fn(Int) -> Bool,
) -> Result(Int, Nil)
Returns the first byte matching predicate, or Error(Nil) if none
match.
pub fn find_index(
in array: Uint8Array,
one_that predicate: fn(Int) -> Bool,
) -> Result(Int, Nil)
Returns the index of the first byte matching predicate, or
Error(Nil) if none match.
pub fn find_last(
in array: Uint8Array,
one_that predicate: fn(Int) -> Bool,
) -> Result(Int, Nil)
Returns the last byte matching predicate, or Error(Nil) if none
match.
pub fn find_last_index(
in array: Uint8Array,
one_that predicate: fn(Int) -> Bool,
) -> Result(Int, Nil)
Returns the index of the last byte matching predicate, or
Error(Nil) if none match.
pub fn for_each(
in array: Uint8Array,
run callback: fn(Int) -> b,
) -> Nil
pub fn from_base64(
string: String,
) -> Result(Uint8Array, js_error.JsError)
Decodes a base64 string into a Uint8Array. Returns an error if
string is not valid base64.
pub fn from_buffer(
buffer: array_buffer.ArrayBuffer,
) -> Uint8Array
pub fn from_buffer_range(
buffer: array_buffer.ArrayBuffer,
byte_offset byte_offset: Int,
length length: Int,
) -> Result(Uint8Array, js_error.JsError)
Creates a Uint8Array view over a slice of buffer starting at
byte_offset and spanning length elements. Returns an error if
the range is out of bounds or buffer is detached.
pub fn from_hex(
string: String,
) -> Result(Uint8Array, js_error.JsError)
Decodes a hex string into a Uint8Array. Returns an error if string
is not valid hex (non-hex characters or odd length).
pub fn from_length(
length: Int,
) -> Result(Uint8Array, js_error.JsError)
Creates a zero-filled Uint8Array of the given length. Returns an error
if length is negative or exceeds the maximum allocatable size.
pub fn from_list(list: List(Int)) -> Uint8Array
Creates a Uint8Array from a list of byte values. Values outside
0–255 are wrapped modulo 256, matching the JS Uint8Array
constructor — from_list([257]) yields a one-byte array containing
1.
pub fn from_list_mapped(
list: List(a),
with mapper: fn(a) -> Int,
) -> Uint8Array
pub fn includes(in array: Uint8Array, value value: Int) -> Bool
pub fn includes_from(
in array: Uint8Array,
value value: Int,
from index: Int,
) -> Bool
pub fn index_every(
in array: Uint8Array,
satisfying predicate: fn(Int, Int) -> Bool,
) -> Bool
pub fn index_filter(
in array: Uint8Array,
keeping predicate: fn(Int, Int) -> Bool,
) -> Uint8Array
pub fn index_find(
in array: Uint8Array,
one_that predicate: fn(Int, Int) -> Bool,
) -> Result(Int, Nil)
Like find, but passes the index alongside each byte to predicate.
pub fn index_find_index(
in array: Uint8Array,
one_that predicate: fn(Int, Int) -> Bool,
) -> Result(Int, Nil)
Like find_index, but passes the index alongside each byte to
predicate.
pub fn index_find_last(
in array: Uint8Array,
one_that predicate: fn(Int, Int) -> Bool,
) -> Result(Int, Nil)
Like find_last, but passes the index alongside each byte to
predicate.
pub fn index_find_last_index(
in array: Uint8Array,
one_that predicate: fn(Int, Int) -> Bool,
) -> Result(Int, Nil)
Like find_last_index, but passes the index alongside each byte to
predicate.
pub fn index_for_each(
in array: Uint8Array,
run callback: fn(Int, Int) -> b,
) -> Nil
pub fn index_map(
over array: Uint8Array,
with callback: fn(Int, Int) -> Int,
) -> Uint8Array
pub fn index_of(
in array: Uint8Array,
value value: Int,
) -> Result(Int, Nil)
Returns the first index of value, or Error(Nil) if not present.
pub fn index_of_from(
in array: Uint8Array,
value value: Int,
from index: Int,
) -> Result(Int, Nil)
Like index_of, but starts searching from index.
pub fn index_reduce(
over array: Uint8Array,
from initial: a,
with callback: fn(a, Int, Int) -> a,
) -> a
pub fn index_reduce_right(
over array: Uint8Array,
from initial: a,
with callback: fn(a, Int, Int) -> a,
) -> a
pub fn index_some(
in array: Uint8Array,
satisfying predicate: fn(Int, Int) -> Bool,
) -> Bool
pub fn join(array: Uint8Array, with separator: String) -> String
pub fn keys(
of array: Uint8Array,
) -> iterator.Iterator(Int, Nil, Nil)
pub fn last_index_of(
in array: Uint8Array,
value value: Int,
) -> Result(Int, Nil)
Returns the last index of value, or Error(Nil) if not present.
pub fn last_index_of_from(
in array: Uint8Array,
value value: Int,
from index: Int,
) -> Result(Int, Nil)
Like last_index_of, but searches backwards from index.
pub fn length(of array: Uint8Array) -> Int
pub fn map(
over array: Uint8Array,
with callback: fn(Int) -> Int,
) -> Uint8Array
pub fn new() -> Uint8Array
pub fn reduce(
over array: Uint8Array,
from initial: a,
with callback: fn(a, Int) -> a,
) -> a
pub fn reduce_right(
over array: Uint8Array,
from initial: a,
with callback: fn(a, Int) -> a,
) -> a
pub fn reverse(array: Uint8Array) -> Uint8Array
pub fn set(
in array: Uint8Array,
values values: Uint8Array,
) -> Result(Nil, js_error.JsError)
Copies values into array starting at index 0. Returns an error if
values would extend past the end of array.
pub fn set_from_base64(
array: Uint8Array,
string: String,
) -> Result(#(Int, Int), js_error.JsError)
Decodes string as base64 into array in place. Returns the number
of characters read and bytes written. Returns an error if string is
not valid base64.
pub fn set_from_hex(
array: Uint8Array,
string: String,
) -> Result(#(Int, Int), js_error.JsError)
Decodes string as hex into array in place. Returns the number of
characters read and bytes written. Returns an error if string is not
valid hex.
pub fn set_with_offset(
in array: Uint8Array,
values values: Uint8Array,
offset offset: Int,
) -> Result(Nil, js_error.JsError)
Copies values into array starting at offset. Returns an error if
offset is negative or the copy would extend past the end of array.
pub fn slice(array: Uint8Array) -> Uint8Array
pub fn slice_from(array: Uint8Array, start: Int) -> Uint8Array
pub fn slice_range(
array: Uint8Array,
from start: Int,
to end: Int,
) -> Uint8Array
pub fn some(
in array: Uint8Array,
satisfying predicate: fn(Int) -> Bool,
) -> Bool
pub fn sort(
array: Uint8Array,
by compare: fn(Int, Int) -> order.Order,
) -> Uint8Array
pub fn subarray(
array: Uint8Array,
from begin: Int,
to end: Int,
) -> Uint8Array
pub fn to_base64(array: Uint8Array) -> String
pub fn to_hex(array: Uint8Array) -> String
pub fn to_list(array: Uint8Array) -> List(Int)
pub fn to_reversed(array: Uint8Array) -> Uint8Array
pub fn to_sorted(
array: Uint8Array,
by compare: fn(Int, Int) -> order.Order,
) -> Uint8Array
pub fn values(
of array: Uint8Array,
) -> iterator.Iterator(Int, Nil, Nil)
pub fn with(
array: Uint8Array,
at_index index: Int,
value value: Int,
) -> Result(Uint8Array, js_error.JsError)
Returns a copy of the array with the byte at index replaced by
value. Negative indices count from the end. Returns an error if
index is out of bounds.