Blob

A blob is an immutable sequences of bytes. Blobs are similar to arrays of bytes [Nat8].

The convention is to name the module alias after the file name it is defined in:

import Blob "mo:base/Blob";

Conversion

Function fromArray
Function toArray
Function toArrayMut
Function fromArrayMut

Utility Function

Function hash

Comparison

Function compare
Function equal
Function notEqual
Function less
Function lessOrEqual
Function greater
Function greaterOrEqual

Blob.fromArray

func fromArray(bytes : [Nat8]) : Blob
import Blob "mo:base/Blob";

let a : [Nat8] = [253, 254, 255];

Blob.fromArray(a);

Blob.toArray

func toArray(blob : Blob) : [Nat8]
import Blob "mo:base/Blob";

let blob : Blob = "\0a\0b\0c" : Blob;

Blob.toArray(blob);

Blob.toArrayMut

func toArrayMut(blob : Blob) : [var Nat8]
import Blob "mo:base/Blob";

let blob : Blob = "\0a\0b\0c" : Blob;

Blob.toArrayMut(blob);

Blob.fromArrayMut

func fromArrayMut(bytes : [var Nat8]) : Blob
import Blob "mo:base/Blob";

let a : [var Nat8] = [var 253, 254, 255];

Blob.fromArrayMut(a);

Blob.hash

func hash(blob : Blob) : Nat32

The function hash takes one Blob value and returns a Nat32 value.

import Blob "mo:base/Blob";

let blob : Blob = "\00\ff\00" : Blob;

Blob.hash(blob);

Blob.compare

func compare(blob1 : Blob, blob2 : Blob) : {#less; #equal; #greater}

The function compare takes two Blob value and returns an Order value.

import Blob "mo:base/Blob";

let blob1 : Blob = "\00\ef\00" : Blob;
let blob2 : Blob = "\00\ff\00" : Blob;

Blob.compare(blob1, blob2);

Blob.equal

func equal(blob1 : Blob, blob2 : Blob) : Bool

The function equal takes two Blob value and returns a Bool value.

import Blob "mo:base/Blob";

let blob1 : Blob = "\00\ff\00" : Blob;
let blob2 : Blob = "\00\ff\00" : Blob;

Blob.equal(blob1, blob2);

Blob.notEqual

func notEqual(blob1 : Blob, blob2 : Blob) : Bool

The function notEqual takes two Blob value and returns a Bool value.

import Blob "mo:base/Blob";

let blob1 : Blob = "\00\ff\00" : Blob;
let blob2 : Blob = "\00\ef\00" : Blob;

Blob.notEqual(blob1, blob2);

Blob.less

func less(blob1 : Blob, blob2 : Blob) : Bool

The function less takes two Blob value and returns a Bool value.

import Blob "mo:base/Blob";

let blob1 : Blob = "\00\ef\00" : Blob;
let blob2 : Blob = "\00\ff\00" : Blob;

Blob.less(blob1, blob2);

Blob.lessOrEqual

func lessOrEqual(blob1 : Blob, blob2 : Blob) : Bool

The function lessOrEqual takes two Blob value and returns a Bool value.

import Blob "mo:base/Blob";

let blob1 : Blob = "\00\ef\00" : Blob;
let blob2 : Blob = "\00\ff\00" : Blob;

Blob.lessOrEqual(blob1, blob2);

Blob.greater

func greater(blob1 : Blob, blob2 : Blob) : Bool

The function greater takes two Blob value and returns a Bool value.

import Blob "mo:base/Blob";

let blob1 : Blob = "\00\ff\00" : Blob;
let blob2 : Blob = "\00\ef\00" : Blob;

Blob.greater(blob1, blob2);

Blob.greaterOrEqual

func greaterOrEqual(blob1 : Blob, blob2 : Blob) : Bool

The function greaterOrEqual takes two Blob value and returns a Bool value.

import Blob "mo:base/Blob";

let blob1 : Blob = "\00\ff\00" : Blob;
let blob2 : Blob = "\00\ef\00" : Blob;

Blob.greaterOrEqual(blob1, blob2);