mirror of
https://github.com/Instadapp/Swap-Aggregator-Subgraph.git
synced 2024-07-29 21:57:12 +00:00
123 lines
3.5 KiB
Markdown
123 lines
3.5 KiB
Markdown
# IPFS Block JavaScript Implementation
|
|
|
|
[](http://ipn.io)
|
|
[](http://ipfs.io/)
|
|
[](http://webchat.freenode.net/?channels=%23ipfs)
|
|
[](https://github.com/RichardLitt/standard-readme)
|
|
[](https://travis-ci.com/ipfs/js-ipfs-block)
|
|
[](https://coveralls.io/github/ipfs/js-ipfs-block?branch=master)
|
|
[](https://david-dm.org/ipfs/js-ipfs-block)
|
|
[](https://github.com/feross/standard)
|
|

|
|

|
|
|
|
> [IPFS][ipfs] implementation of the Block data structure in JavaScript.
|
|
|
|
**Block** - A block is a blob of binary data.
|
|
|
|
## Lead Maintainer
|
|
|
|
[Volker Mische](https://github.com/vmx)
|
|
|
|
## Table of Contents
|
|
|
|
- [Install](#install)
|
|
- [npm](#npm)
|
|
- [Usage](#usage)
|
|
- [Node.js](#nodejs)
|
|
- [Example](#example)
|
|
- [Browser: Browserify, Webpack, other bundlers](#browser-browserify-webpack-other-bundlers)
|
|
- [Browser: `<script>` Tag](#browser-script-tag)
|
|
- [API](#api)
|
|
- [Block](#block)
|
|
- [`new Block(data, cid)`](#new-blockdata-cid)
|
|
- [`block.data`](#blockdata)
|
|
- [`block.cid`](#blockcid)
|
|
- [Contribute](#contribute)
|
|
- [License](#license)
|
|
|
|
## Install
|
|
|
|
### npm
|
|
|
|
```sh
|
|
> npm install ipfs-block
|
|
```
|
|
|
|
## Usage
|
|
|
|
### Node.js
|
|
|
|
```js
|
|
const Block = require('ipfs-block')
|
|
```
|
|
|
|
#### Example
|
|
|
|
```js
|
|
const Block = require('ipfs-block')
|
|
|
|
// create a block
|
|
const block = new Block(new Buffer('hello world'), cid)
|
|
console.log(block.data.toString())
|
|
```
|
|
|
|
### Browser: Browserify, Webpack, other bundlers
|
|
|
|
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.
|
|
|
|
```js
|
|
const Block = require('ipfs-block')
|
|
```
|
|
|
|
### Browser: `<script>` Tag
|
|
|
|
Loading this module through a script tag will make the `IpfsBlock` obj available in
|
|
the global namespace.
|
|
|
|
```html
|
|
<script src="https://unpkg.com/ipfs-block/dist/index.min.js"></script>
|
|
<!-- OR -->
|
|
<script src="https://unpkg.com/ipfs-block/dist/index.js"></script>
|
|
```
|
|
|
|
## API
|
|
|
|
```js
|
|
const Block = require('ipfs-block')
|
|
```
|
|
|
|
### Block
|
|
|
|
#### `new Block(data, cid)`
|
|
|
|
- `data: Buffer`
|
|
|
|
Creates a new block with raw data `data`.
|
|
|
|
#### `block.data`
|
|
|
|
The raw data of the block. Its format matches whatever was provided in its constructor.
|
|
|
|
#### `block.cid`
|
|
|
|
The cid of the block.
|
|
|
|
[ipfs]: https://ipfs.io
|
|
[multihash]: https://github.com/jbenet/js-multihash
|
|
|
|
## Contribute
|
|
|
|
Feel free to join in. All welcome. Open an [issue](https://github.com/ipfs/js-ipfs-block/issues)!
|
|
|
|
This repository falls under the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).
|
|
|
|
[](https://github.com/ipfs/community/blob/master/contributing.md)
|
|
|
|
## License
|
|
|
|
[MIT](LICENSE)
|