ipld-block
Version:
JavaScript Implementation of IPLD Block
230 lines (229 loc) • 13.8 kB
HTML
<html class="default no-js">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>ipld-block - v0.11.1</title>
<meta name="description" content="Documentation for ipld-block - v0.11.1">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="assets/css/main.css">
<script async src="assets/js/search.js" id="search-script"></script>
</head>
<body>
<header>
<div class="tsd-page-toolbar">
<div class="container">
<div class="table-wrap">
<div class="table-cell" id="tsd-search" data-index="assets/js/search.json" data-base=".">
<div class="field">
<label for="tsd-search-field" class="tsd-widget search no-caption">Search</label>
<input id="tsd-search-field" type="text" />
</div>
<ul class="results">
<li class="state loading">Preparing search index...</li>
<li class="state failure">The search index is not available</li>
</ul>
<a href="index.html" class="title">ipld-block - v0.11.1</a>
</div>
<div class="table-cell" id="tsd-widgets">
<div id="tsd-filter">
<a href="#" class="tsd-widget options no-caption" data-toggle="options">Options</a>
<div class="tsd-filter-group">
<div class="tsd-select" id="tsd-filter-visibility">
<span class="tsd-select-label">All</span>
<ul class="tsd-select-list">
<li data-value="public">Public</li>
<li data-value="protected">Public/Protected</li>
<li data-value="private" class="selected">All</li>
</ul>
</div>
<input type="checkbox" id="tsd-filter-inherited" checked />
<label class="tsd-widget" for="tsd-filter-inherited">Inherited</label>
<input type="checkbox" id="tsd-filter-externals" checked />
<label class="tsd-widget" for="tsd-filter-externals">Externals</label>
</div>
</div>
<a href="#" class="tsd-widget menu no-caption" data-toggle="menu">Menu</a>
</div>
</div>
</div>
</div>
<div class="tsd-page-title">
<div class="container">
<h1>ipld-block - v0.11.1</h1>
</div>
</div>
</header>
<div class="container container-main">
<div class="row">
<div class="col-8 col-content">
<div class="tsd-panel tsd-typography">
<a href="#ipld-block-javascript-implementation" id="ipld-block-javascript-implementation" style="color: inherit; text-decoration: none;">
<h1>IPLD Block JavaScript Implementation</h1>
</a>
<p><a href="http://ipn.io"><img src="https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square" alt=""></a>
<a href="http://ipld.io/"><img src="https://img.shields.io/badge/project-IPLD-blue.svg?style=flat-square" alt=""></a>
<a href="http://webchat.freenode.net/?channels=%23ipld"><img src="https://img.shields.io/badge/freenode-%23ipld-blue.svg?style=flat-square" alt=""></a>
<a href="https://github.com/RichardLitt/standard-readme"><img src="https://img.shields.io/badge/standard--readme-OK-green.svg?style=flat-square" alt="standard-readme compliant"></a>
<a href="https://travis-ci.com/ipld/js-ipld-block"><img src="https://flat.badgen.net/travis/ipld/js-ipld-block" alt="Travis CI"></a>
<a href="https://coveralls.io/github/ipld/js-ipld-block?branch=master"><img src="https://coveralls.io/repos/github/ipld/js-ipld-block/badge.svg?branch=master" alt="Coverage Status"></a>
<a href="https://david-dm.org/ipld/js-ipld-block"><img src="https://david-dm.org/ipld/js-ipld-block.svg?style=flat-square" alt="Dependency Status"></a>
<a href="https://github.com/feross/standard"><img src="https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square" alt="js-standard-style"></a>
<img src="https://img.shields.io/badge/npm-%3E%3D3.0.0-orange.svg?style=flat-square" alt="">
<img src="https://img.shields.io/badge/Node.js-%3E%3D4.0.0-orange.svg?style=flat-square" alt=""></p>
<blockquote>
<p><a href="https://ipld.io/">IPLD</a> implementation of the Block data structure in JavaScript.</p>
</blockquote>
<p><strong>Block</strong> - A block is a blob of binary data combined with a <a href="https://github.com/multiformats/js-cid">CID</a>.</p>
<a href="#lead-maintainer" id="lead-maintainer" style="color: inherit; text-decoration: none;">
<h2>Lead Maintainer</h2>
</a>
<p><a href="https://github.com/vmx">Volker Mische</a></p>
<a href="#table-of-contents" id="table-of-contents" style="color: inherit; text-decoration: none;">
<h2>Table of Contents</h2>
</a>
<ul>
<li><a href="#ipld-block-javascript-implementation">IPLD Block JavaScript Implementation</a><ul>
<li><a href="#lead-maintainer">Lead Maintainer</a></li>
<li><a href="#table-of-contents">Table of Contents</a></li>
<li><a href="#install">Install</a><ul>
<li><a href="#npm">npm</a></li>
</ul>
</li>
<li><a href="#usage">Usage</a><ul>
<li><a href="#nodejs">Node.js</a><ul>
<li><a href="#example">Example</a></li>
</ul>
</li>
<li><a href="#browser-browserify-webpack-other-bundlers">Browser: Browserify, Webpack, other bundlers</a></li>
<li><a href="#browser-script-tag">Browser: <code><script></code> Tag</a></li>
</ul>
</li>
<li><a href="#api">API</a><ul>
<li><a href="#block">Block</a><ul>
<li><a href="#new-blockdata-cid"><code>new Block(data, cid)</code></a></li>
<li><a href="#blockdata"><code>block.data</code></a></li>
<li><a href="#blockcid"><code>block.cid</code></a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#contribute">Contribute</a></li>
<li><a href="#license">License</a></li>
</ul>
</li>
</ul>
<a href="#install" id="install" style="color: inherit; text-decoration: none;">
<h2>Install</h2>
</a>
<a href="#npm" id="npm" style="color: inherit; text-decoration: none;">
<h3>npm</h3>
</a>
<pre><code class="language-sh"><span style="color: #000000">> npm install ipld-block</span>
</code></pre>
<a href="#usage" id="usage" style="color: inherit; text-decoration: none;">
<h2>Usage</h2>
</a>
<a href="#nodejs" id="nodejs" style="color: inherit; text-decoration: none;">
<h3>Node.js</h3>
</a>
<pre><code class="language-js"><span style="color: #0000FF">const</span><span style="color: #000000"> </span><span style="color: #0070C1">Block</span><span style="color: #000000"> = </span><span style="color: #795E26">require</span><span style="color: #000000">(</span><span style="color: #A31515">'ipld-block'</span><span style="color: #000000">)</span>
</code></pre>
<a href="#example" id="example" style="color: inherit; text-decoration: none;">
<h4>Example</h4>
</a>
<pre><code class="language-js"><span style="color: #0000FF">const</span><span style="color: #000000"> </span><span style="color: #0070C1">Block</span><span style="color: #000000"> = </span><span style="color: #795E26">require</span><span style="color: #000000">(</span><span style="color: #A31515">'ipld-block'</span><span style="color: #000000">)</span>
<span style="color: #0000FF">const</span><span style="color: #000000"> </span><span style="color: #0070C1">encoder</span><span style="color: #000000"> = </span><span style="color: #0000FF">new</span><span style="color: #000000"> </span><span style="color: #795E26">TextEncoder</span><span style="color: #000000">(</span><span style="color: #A31515">'utf8'</span><span style="color: #000000">)</span>
<span style="color: #008000">// create a block</span>
<span style="color: #0000FF">const</span><span style="color: #000000"> </span><span style="color: #0070C1">block</span><span style="color: #000000"> = </span><span style="color: #0000FF">new</span><span style="color: #000000"> </span><span style="color: #795E26">Block</span><span style="color: #000000">(</span><span style="color: #001080">encoder</span><span style="color: #000000">.</span><span style="color: #795E26">encode</span><span style="color: #000000">(</span><span style="color: #A31515">'hello world'</span><span style="color: #000000">), </span><span style="color: #001080">cid</span><span style="color: #000000">)</span>
<span style="color: #001080">console</span><span style="color: #000000">.</span><span style="color: #795E26">log</span><span style="color: #000000">(</span><span style="color: #001080">block</span><span style="color: #000000">.</span><span style="color: #001080">data</span><span style="color: #000000">.</span><span style="color: #795E26">toString</span><span style="color: #000000">())</span>
</code></pre>
<a href="#browser-browserify-webpack-other-bundlers" id="browser-browserify-webpack-other-bundlers" style="color: inherit; text-decoration: none;">
<h3>Browser: Browserify, Webpack, other bundlers</h3>
</a>
<p>The code published to npm that gets loaded on require is in fact a ES5
transpiled version with the right shims added. This means that you can require
it and use with your favourite bundler without having to adjust asset management
process.</p>
<pre><code class="language-js"><span style="color: #0000FF">const</span><span style="color: #000000"> </span><span style="color: #0070C1">Block</span><span style="color: #000000"> = </span><span style="color: #795E26">require</span><span style="color: #000000">(</span><span style="color: #A31515">'ipld-block'</span><span style="color: #000000">)</span>
</code></pre>
<a href="#browser-ltscriptgt-tag" id="browser-ltscriptgt-tag" style="color: inherit; text-decoration: none;">
<h3>Browser: <code><script></code> Tag</h3>
</a>
<p>Loading this module through a script tag will make the <code>IpldBlock</code> obj available in
the global namespace.</p>
<pre><code class="language-html"><span style="color: #800000"><script</span><span style="color: #000000FF"> </span><span style="color: #FF0000">src</span><span style="color: #000000FF">=</span><span style="color: #0000FF">"https://unpkg.com/ipld-block/dist/index.min.js"</span><span style="color: #800000">></script></span>
<span style="color: #008000"><!-- OR --></span>
<span style="color: #800000"><script</span><span style="color: #000000FF"> </span><span style="color: #FF0000">src</span><span style="color: #000000FF">=</span><span style="color: #0000FF">"https://unpkg.com/ipld-block/dist/index.js"</span><span style="color: #800000">></script></span>
</code></pre>
<a href="#api" id="api" style="color: inherit; text-decoration: none;">
<h2>API</h2>
</a>
<pre><code class="language-js"><span style="color: #0000FF">const</span><span style="color: #000000"> </span><span style="color: #0070C1">Block</span><span style="color: #000000"> = </span><span style="color: #795E26">require</span><span style="color: #000000">(</span><span style="color: #A31515">'ipld-block'</span><span style="color: #000000">)</span>
</code></pre>
<a href="#block" id="block" style="color: inherit; text-decoration: none;">
<h3>Block</h3>
</a>
<a href="#new-blockdata-cid" id="new-blockdata-cid" style="color: inherit; text-decoration: none;">
<h4><code>new Block(data, cid)</code></h4>
</a>
<ul>
<li><code>data: Uint8Array</code></li>
</ul>
<p>Creates a new block with raw data <code>data</code>.</p>
<a href="#blockdata" id="blockdata" style="color: inherit; text-decoration: none;">
<h4><code>block.data</code></h4>
</a>
<p>The raw data of the block. Its format matches whatever was provided in its constructor.</p>
<a href="#blockcid" id="blockcid" style="color: inherit; text-decoration: none;">
<h4><code>block.cid</code></h4>
</a>
<p>The cid of the block.</p>
<a href="#contribute" id="contribute" style="color: inherit; text-decoration: none;">
<h2>Contribute</h2>
</a>
<p>Feel free to join in. All welcome. Open an <a href="https://github.com/ipld/js-ipld-block/issues">issue</a>!</p>
<p>This repository falls under the IPFS <a href="https://github.com/ipfs/community/blob/master/code-of-conduct.md">Code of Conduct</a>.</p>
<p><a href="https://github.com/ipfs/community/blob/master/contributing.md"><img src="https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif" alt=""></a></p>
<a href="#license" id="license" style="color: inherit; text-decoration: none;">
<h2>License</h2>
</a>
<p><a href="LICENSE">MIT</a></p>
</div>
</div>
<div class="col-4 col-menu menu-sticky-wrap menu-highlight">
<nav class="tsd-navigation primary">
<ul>
<li class=" ">
<a href="modules.html">Exports</a>
</li>
</ul>
</nav>
<nav class="tsd-navigation secondary menu-sticky">
<ul class="before-current">
<li class=" tsd-kind-class">
<a href="classes/block.html" class="tsd-kind-icon">Block</a>
</li>
</ul>
</nav>
</div>
</div>
</div>
<footer>
<div class="container">
<h2>Legend</h2>
<div class="tsd-legend-group">
<ul class="tsd-legend">
<li class="tsd-kind-constructor tsd-parent-kind-class"><span class="tsd-kind-icon">Constructor</span></li>
<li class="tsd-kind-property tsd-parent-kind-class"><span class="tsd-kind-icon">Property</span></li>
</ul>
<ul class="tsd-legend">
<li class="tsd-kind-method tsd-parent-kind-class tsd-is-static"><span class="tsd-kind-icon">Static method</span></li>
</ul>
</div>
</div>
</footer>
<div class="overlay"></div>
<script src="assets/js/main.js"></script>
</body>
</html>