Blob Library (Blob)
Linked to the blob type — the raw-bytes counterpart to str, useful anywhere binary data crosses a boundary (blobify, Http, fs, images).
Byte Access
Blob::at(bytes: blob, index: int) -> int
The byte value at an index.
Blob::len(bytes: blob) -> int
Blob::size(bytes: blob) -> bytes
Same as len, but as a bytes unit value instead of a plain int.
blob-size.stofPlayground ↗
#[main]
fn main() {
const bytes: blob = "hello";
pln(bytes.size());
}Output
Encoding & Decoding
Blob::utf8(bytes: blob) -> str
The default conversion for a plain as str cast too.
blob-utf8.stofPlayground ↗
#[main]
fn main() {
const bytes: blob = "hello";
pln(bytes.utf8(), ' ', bytes as str);
}Output
Blob::from_utf8(val: str) -> blob
blob-from-utf8.stofPlayground ↗
#[main]
fn main() {
pln(Blob::from_utf8("hello") == ("hello" as blob));
}Output
Blob::base64(bytes: blob) -> str
blob-base64.stofPlayground ↗
#[main]
fn main() {
const bytes: blob = "hello";
pln(bytes.base64());
}Output
Blob::from_base64(val: str) -> blob
blob-from-base64.stofPlayground ↗
#[main]
fn main() {
const bytes: blob = Blob::from_base64("aGVsbG8=");
pln(bytes as str);
}Output
Blob::url_base64(bytes: blob) -> str
URL-safe Base64 — swaps the characters that aren't URL-safe in standard Base64.
blob-url-base64.stofPlayground ↗
#[main]
fn main() {
const bytes: blob = "hello";
pln(bytes.url_base64());
}Output
Blob::from_url_base64(val: str) -> blob
blob-from-url-base64.stofPlayground ↗
#[main]
fn main() {
const bytes: blob = Blob::from_url_base64("aGVsbG8=");
pln(bytes as str);
}Output