-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
45 changed files
with
7,481 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
<!DOCTYPE html> | ||
<html><head title="Doc"><meta charset="UTF-8"/><link href="styles.css" rel="stylesheet"/></head><body><nav class="sidebar"><h3>Modules</h3><ul><li><li><a href="Array.html">Array</a></li></li><li><li><a href="Blob.html">Blob</a></li></li><li><li><a href="Bool.html">Bool</a></li></li><li><li><a href="CertifiedData.html">CertifiedData</a></li></li><li><li><a href="Char.html">Char</a></li></li><li><li><a href="Cycles.html">Cycles</a></li></li><li><li><a href="Debug.html">Debug</a></li></li><li><li><a href="Error.html">Error</a></li></li><li><li><a href="Float.html">Float</a></li></li><li><li><a href="Func.html">Func</a></li></li><li><li><a href="Int.html">Int</a></li></li><li><li><a href="Int16.html">Int16</a></li></li><li><li><a href="Int32.html">Int32</a></li></li><li><li><a href="Int64.html">Int64</a></li></li><li><li><a href="Int8.html">Int8</a></li></li><li><li><a href="InternetComputer.html">InternetComputer</a></li></li><li><li><a href="Iter.html">Iter</a></li></li><li><li><a href="List.html">List</a></li></li><li><li><a href="Map.html">Map</a></li></li><li><li><a href="Nat.html">Nat</a></li></li><li><li><a href="Nat16.html">Nat16</a></li></li><li><li><a href="Nat32.html">Nat32</a></li></li><li><li><a href="Nat64.html">Nat64</a></li></li><li><li><a href="Nat8.html">Nat8</a></li></li><li><li><a href="Option.html">Option</a></li></li><li><li><a href="Order.html">Order</a></li></li><li><li><a href="Principal.html">Principal</a></li></li><li><li><a href="Queue.html">Queue</a></li></li><li><li><a href="Random.html">Random</a></li></li><li><li><a href="Region.html">Region</a></li></li><li><li><a href="Result.html">Result</a></li></li><li><li><a href="Runtime.html">Runtime</a></li></li><li><li><a href="Set.html">Set</a></li></li><li><li><a href="Stack.html">Stack</a></li></li><li><li><a href="Text.html">Text</a></li></li><li><li><a href="Time.html">Time</a></li></li><li><li><a href="Timer.html">Timer</a></li></li><li><li><a href="Types.html">Types</a></li></li><li><li><a href="VarArray.html">VarArray</a></li></li><li><li><a href="immutable/Map.html">immutable/Map</a></li></li><li><li><a href="immutable/Queue.html">immutable/Queue</a></li></li><li><li><a href="immutable/Set.html">immutable/Set</a></li></li><li><li><a href="immutable/Stack.html">immutable/Stack</a></li></li></ul><h3>Declarations</h3><ul><li><li><a href="#type.Blob">Blob</a></li></li><li><li><a href="#empty">empty</a></li></li><li><li><a href="#size">size</a></li></li><li><li><a href="#fromArray">fromArray</a></li></li><li><li><a href="#fromVarArray">fromVarArray</a></li></li><li><li><a href="#toArray">toArray</a></li></li><li><li><a href="#toVarArray">toVarArray</a></li></li><li><li><a href="#hash">hash</a></li></li><li><li><a href="#compare">compare</a></li></li><li><li><a href="#equal">equal</a></li></li><li><li><a href="#notEqual">notEqual</a></li></li><li><li><a href="#less">less</a></li></li><li><li><a href="#lessOrEqual">lessOrEqual</a></li></li><li><li><a href="#greater">greater</a></li></li><li><li><a href="#greaterOrEqual">greaterOrEqual</a></li></li></ul></nav><div class="documentation"><h1>Blob</h1><p>Module for working with Blobs (immutable sequences of bytes).</p> | ||
<p>Blobs represent sequences of bytes. They are immutable, iterable, but not indexable and can be empty.</p> | ||
<p>Byte sequences are also often represented as <code>[Nat8]</code>, i.e. an array of bytes, but this representation is currently much less compact than <code>Blob</code>, taking 4 physical bytes to represent each logical byte in the sequence. | ||
If you would like to manipulate Blobs, it is recommended that you convert | ||
Blobs to <code>[var Nat8]</code> or <code>Buffer<Nat8></code>, do the manipulation, then convert back.</p> | ||
<p>Import from the base library to use this module.</p> | ||
<pre><code>motoko name=import | ||
import Blob "mo:base/Blob";</code></pre> | ||
|
||
<p>Some built in features not listed in this module:</p> | ||
<ul><li>You can create a <code>Blob</code> literal from a <code>Text</code> literal, provided the context expects an expression of type <code>Blob</code>.</li><li><code>b.size() : Nat</code> returns the number of bytes in the blob <code>b</code>;</li><li><code>b.values() : Iter.Iter<Nat8></code> returns an iterator to enumerate the bytes of the blob <code>b</code>.</li></ul> | ||
|
||
<p>For example:</p> | ||
<pre><code>motoko include=import | ||
import Debug "mo:base/Debug"; | ||
import Nat8 "mo:base/Nat8"; | ||
|
||
let blob = "\00\00\00\ff" : Blob; // blob literals, where each byte is delimited by a back-slash and represented in hex | ||
let blob2 = "charsもあり" : Blob; // you can also use characters in the literals | ||
let numBytes = blob.size(); // => 4 (returns the number of bytes in the Blob) | ||
for (byte : Nat8 in blob.values()) { // iterator over the Blob | ||
Debug.print(Nat8.toText(byte)) | ||
}</code></pre><div class="declaration"><h4 class="type-declaration" id="type.Blob"><span class="keyword">type </span><span class="type">Blob</span> = <span class="type">Prim.Types.Blob</span></h4><p></p></div><div class="declaration"><h4 class="function" id="empty"><code><span class="keyword">public func </span><span class="fnname">empty</span>() : <a href="#type.Blob"><span class="type">Blob</span></a></code></h4><p><p>Returns an empty <code>Blob</code> (equivalent to <code>""</code>).</p> | ||
</p></div><div class="declaration"><h4 class="function" id="size"><code><span class="keyword">public func </span><span class="fnname">size</span>(<span class="parameter">blob</span> : <a href="#type.Blob"><span class="type">Blob</span></a>) : <span class="type">Nat</span></code></h4><p></p></div><div class="declaration"><h4 class="function" id="fromArray"><code><span class="keyword">public func </span><span class="fnname">fromArray</span>(<span class="parameter">bytes</span> : [<span class="type">Nat8</span>]) : <a href="#type.Blob"><span class="type">Blob</span></a></code></h4><p><p>Creates a <code>Blob</code> from an array of bytes (<code>[Nat8]</code>), by copying each element.</p> | ||
<p>Example:</p> | ||
<pre><code>motoko include=import | ||
let bytes : [Nat8] = [0, 255, 0]; | ||
let blob = Blob.fromArray(bytes); // => "\00\FF\00"</code></pre></p></div><div class="declaration"><h4 class="function" id="fromVarArray"><code><span class="keyword">public func </span><span class="fnname">fromVarArray</span>(<span class="parameter">bytes</span> : [<span class="keyword">var </span><span class="type">Nat8</span>]) : <a href="#type.Blob"><span class="type">Blob</span></a></code></h4><p><p>Creates a <code>Blob</code> from a mutable array of bytes (<code>[var Nat8]</code>), by copying each element.</p> | ||
<p>Example:</p> | ||
<pre><code>motoko include=import | ||
let bytes : [var Nat8] = [var 0, 255, 0]; | ||
let blob = Blob.fromVarArray(bytes); // => "\00\FF\00"</code></pre></p></div><div class="declaration"><h4 class="function" id="toArray"><code><span class="keyword">public func </span><span class="fnname">toArray</span>(<span class="parameter">blob</span> : <a href="#type.Blob"><span class="type">Blob</span></a>) : [<span class="type">Nat8</span>]</code></h4><p><p>Converts a <code>Blob</code> to an array of bytes (<code>[Nat8]</code>), by copying each element.</p> | ||
<p>Example:</p> | ||
<pre><code>motoko include=import | ||
let blob = "\00\FF\00" : Blob; | ||
let bytes = Blob.toArray(blob); // => [0, 255, 0]</code></pre></p></div><div class="declaration"><h4 class="function" id="toVarArray"><code><span class="keyword">public func </span><span class="fnname">toVarArray</span>(<span class="parameter">blob</span> : <a href="#type.Blob"><span class="type">Blob</span></a>) : [<span class="keyword">var </span><span class="type">Nat8</span>]</code></h4><p><p>Converts a <code>Blob</code> to a mutable array of bytes (<code>[var Nat8]</code>), by copying each element.</p> | ||
<p>Example:</p> | ||
<pre><code>motoko include=import | ||
let blob = "\00\FF\00" : Blob; | ||
let bytes = Blob.toVarArray(blob); // => [var 0, 255, 0]</code></pre></p></div><div class="declaration"><h4 class="function" id="hash"><code><span class="keyword">public func </span><span class="fnname">hash</span>(<span class="parameter">blob</span> : <a href="#type.Blob"><span class="type">Blob</span></a>) : <a href="Types.html#type.Hash"><span class="type">Types.Hash</span></a></code></h4><p><p>Returns the (non-cryptographic) hash of <code>blob</code>.</p> | ||
<p>Example:</p> | ||
<pre><code>motoko include=import | ||
let blob = "\00\FF\00" : Blob; | ||
Blob.hash(blob) // => 1_818_567_776</code></pre></p></div><div class="declaration"><h4 class="function" id="compare"><code><span class="keyword">public func </span><span class="fnname">compare</span>(<span class="parameter">b1</span> : <a href="#type.Blob"><span class="type">Blob</span></a>, <span class="parameter">b2</span> : <a href="#type.Blob"><span class="type">Blob</span></a>) : {#less; #equal; #greater}</code></h4><p><p>General purpose comparison function for <code>Blob</code> by comparing the value of | ||
the bytes. Returns the <code>Order</code> (either <code>#less</code>, <code>#equal</code>, or <code>#greater</code>) | ||
by comparing <code>blob1</code> with <code>blob2</code>.</p> | ||
<p>Example:</p> | ||
<pre><code>motoko include=import | ||
let blob1 = "\00\00\00" : Blob; | ||
let blob2 = "\00\FF\00" : Blob; | ||
Blob.compare(blob1, blob2) // => #less</code></pre></p></div><div class="declaration"><h4 class="function" id="equal"><code><span class="keyword">public func </span><span class="fnname">equal</span>(<span class="parameter">blob1</span> : <a href="#type.Blob"><span class="type">Blob</span></a>, <span class="parameter">blob2</span> : <a href="#type.Blob"><span class="type">Blob</span></a>) : <span class="type">Bool</span></code></h4><p><p>Equality function for <code>Blob</code> types. | ||
This is equivalent to <code>blob1 == blob2</code>.</p> | ||
<p>Example:</p> | ||
<pre><code>motoko include=import | ||
let blob1 = "\00\FF\00" : Blob; | ||
let blob2 = "\00\FF\00" : Blob; | ||
ignore Blob.equal(blob1, blob2); | ||
blob1 == blob2 // => true</code></pre> | ||
|
||
<p>Note: The reason why this function is defined in this library (in addition | ||
to the existing <code>==</code> operator) is so that you can use it as a function value | ||
to pass to a higher order function.</p> | ||
<p>Example:</p> | ||
<pre><code>motoko include=import | ||
import Buffer "mo:base/Buffer"; | ||
|
||
let buffer1 = Buffer.Buffer<Blob>(3); | ||
let buffer2 = Buffer.Buffer<Blob>(3); | ||
Buffer.equal(buffer1, buffer2, Blob.equal) // => true</code></pre></p></div><div class="declaration"><h4 class="function" id="notEqual"><code><span class="keyword">public func </span><span class="fnname">notEqual</span>(<span class="parameter">blob1</span> : <a href="#type.Blob"><span class="type">Blob</span></a>, <span class="parameter">blob2</span> : <a href="#type.Blob"><span class="type">Blob</span></a>) : <span class="type">Bool</span></code></h4><p><p>Inequality function for <code>Blob</code> types. | ||
This is equivalent to <code>blob1 != blob2</code>.</p> | ||
<p>Example:</p> | ||
<pre><code>motoko include=import | ||
let blob1 = "\00\AA\AA" : Blob; | ||
let blob2 = "\00\FF\00" : Blob; | ||
ignore Blob.notEqual(blob1, blob2); | ||
blob1 != blob2 // => true</code></pre> | ||
|
||
<p>Note: The reason why this function is defined in this library (in addition | ||
to the existing <code>!=</code> operator) is so that you can use it as a function value | ||
to pass to a higher order function.</p> | ||
</p></div><div class="declaration"><h4 class="function" id="less"><code><span class="keyword">public func </span><span class="fnname">less</span>(<span class="parameter">blob1</span> : <a href="#type.Blob"><span class="type">Blob</span></a>, <span class="parameter">blob2</span> : <a href="#type.Blob"><span class="type">Blob</span></a>) : <span class="type">Bool</span></code></h4><p><p>"Less than" function for <code>Blob</code> types. | ||
This is equivalent to <code>blob1 < blob2</code>.</p> | ||
<p>Example:</p> | ||
<pre><code>motoko include=import | ||
let blob1 = "\00\AA\AA" : Blob; | ||
let blob2 = "\00\FF\00" : Blob; | ||
ignore Blob.less(blob1, blob2); | ||
blob1 < blob2 // => true</code></pre> | ||
|
||
<p>Note: The reason why this function is defined in this library (in addition | ||
to the existing <code><</code> operator) is so that you can use it as a function value | ||
to pass to a higher order function.</p> | ||
</p></div><div class="declaration"><h4 class="function" id="lessOrEqual"><code><span class="keyword">public func </span><span class="fnname">lessOrEqual</span>(<span class="parameter">blob1</span> : <a href="#type.Blob"><span class="type">Blob</span></a>, <span class="parameter">blob2</span> : <a href="#type.Blob"><span class="type">Blob</span></a>) : <span class="type">Bool</span></code></h4><p><p>"Less than or equal to" function for <code>Blob</code> types. | ||
This is equivalent to <code>blob1 <= blob2</code>.</p> | ||
<p>Example:</p> | ||
<pre><code>motoko include=import | ||
let blob1 = "\00\AA\AA" : Blob; | ||
let blob2 = "\00\FF\00" : Blob; | ||
ignore Blob.lessOrEqual(blob1, blob2); | ||
blob1 <= blob2 // => true</code></pre> | ||
|
||
<p>Note: The reason why this function is defined in this library (in addition | ||
to the existing <code><=</code> operator) is so that you can use it as a function value | ||
to pass to a higher order function.</p> | ||
</p></div><div class="declaration"><h4 class="function" id="greater"><code><span class="keyword">public func </span><span class="fnname">greater</span>(<span class="parameter">blob1</span> : <a href="#type.Blob"><span class="type">Blob</span></a>, <span class="parameter">blob2</span> : <a href="#type.Blob"><span class="type">Blob</span></a>) : <span class="type">Bool</span></code></h4><p><p>"Greater than" function for <code>Blob</code> types. | ||
This is equivalent to <code>blob1 > blob2</code>.</p> | ||
<p>Example:</p> | ||
<pre><code>motoko include=import | ||
let blob1 = "\BB\AA\AA" : Blob; | ||
let blob2 = "\00\00\00" : Blob; | ||
ignore Blob.greater(blob1, blob2); | ||
blob1 > blob2 // => true</code></pre> | ||
|
||
<p>Note: The reason why this function is defined in this library (in addition | ||
to the existing <code>></code> operator) is so that you can use it as a function value | ||
to pass to a higher order function.</p> | ||
</p></div><div class="declaration"><h4 class="function" id="greaterOrEqual"><code><span class="keyword">public func </span><span class="fnname">greaterOrEqual</span>(<span class="parameter">blob1</span> : <a href="#type.Blob"><span class="type">Blob</span></a>, <span class="parameter">blob2</span> : <a href="#type.Blob"><span class="type">Blob</span></a>) : <span class="type">Bool</span></code></h4><p><p>"Greater than or equal to" function for <code>Blob</code> types. | ||
This is equivalent to <code>blob1 >= blob2</code>.</p> | ||
<p>Example:</p> | ||
<pre><code>motoko include=import | ||
let blob1 = "\BB\AA\AA" : Blob; | ||
let blob2 = "\00\00\00" : Blob; | ||
ignore Blob.greaterOrEqual(blob1, blob2); | ||
blob1 >= blob2 // => true</code></pre> | ||
|
||
<p>Note: The reason why this function is defined in this library (in addition | ||
to the existing <code>>=</code> operator) is so that you can use it as a function value | ||
to pass to a higher order function.</p> | ||
</p></div></div></body></html> |
Oops, something went wrong.