gleam/bit_array
BitArrays are a sequence of binary data of any length.
Functions
pub fn append(
to first: BitArray,
suffix second: BitArray,
) -> BitArray
Creates a new bit array by joining two bit arrays.
Examples
append(to: from_string("butter"), suffix: from_string("fly"))
// -> from_string("butterfly")
pub fn base16_decode(input: String) -> Result(BitArray, Nil)
pub fn base16_encode(input: BitArray) -> String
pub fn base64_decode(encoded: String) -> Result(BitArray, Nil)
Decodes a base 64 encoded string into a BitArray
.
pub fn base64_encode(input: BitArray, padding: Bool) -> String
Encodes a BitArray into a base 64 encoded string.
pub fn base64_url_decode(
encoded: String,
) -> Result(BitArray, Nil)
Decodes a base 64 encoded string with URL and filename safe alphabet into a BitArray
.
pub fn base64_url_encode(
input: BitArray,
padding: Bool,
) -> String
Encodes a BitArray
into a base 64 encoded string with URL and filename safe alphabet.
pub fn byte_size(x: BitArray) -> Int
Returns an integer which is the number of bytes in the bit array.
pub fn concat(bit_arrays: List(BitArray)) -> BitArray
Creates a new bit array by joining multiple binaries.
Examples
concat([from_string("butter"), from_string("fly")])
// -> from_string("butterfly")
pub fn from_string(x: String) -> BitArray
Converts a UTF-8 String
type into a BitArray
.
pub fn inspect(input: BitArray) -> String
Converts a bit array to a string containing the decimal value of each byte.
Examples
inspect(<<0, 20, 0x20, 255>>)
// -> "<<0, 20, 32, 255>>"
inspect(<<100, 5:3>>)
// -> "<<100, 5:size(3)>>"
pub fn slice(
from string: BitArray,
at position: Int,
take length: Int,
) -> Result(BitArray, Nil)
Extracts a sub-section of a bit array.
The slice will start at given position and continue up to specified length. A negative length can be used to extract bytes at the end of a bit array.
This function runs in constant time.