This repository was archived by the owner on Aug 11, 2021. It is now read-only.
File tree 1 file changed +14
-8
lines changed
1 file changed +14
-8
lines changed Original file line number Diff line number Diff line change @@ -25,7 +25,6 @@ backed by an [IPFS Repo][repo] as its datastore for blocks, and uses [Bitswap][b
25
25
┌────────────────────┐
26
26
│ BlockService │
27
27
└────────────────────┘
28
- │
29
28
┌─────┴─────┐
30
29
▼ ▼
31
30
┌─────────┐ ┌───────┐
@@ -51,7 +50,7 @@ backed by an [IPFS Repo][repo] as its datastore for blocks, and uses [Bitswap][b
51
50
### npm
52
51
53
52
``` sh
54
- > npm i ipfs-block-service
53
+ > npm install ipfs-block-service
55
54
```
56
55
57
56
## Usage
@@ -75,19 +74,26 @@ const repo = new IPFSRepo('example')
75
74
76
75
// create a block
77
76
const data = new Buffer (' hello world' )
78
- multihashing (data, ' sha2-256' , (err , hash ) => {
79
- if (err) throw err
77
+ multihashing (data, ' sha2-256' , (err , multihash ) => {
78
+ if (err) {
79
+ throw err
80
+ }
80
81
81
- const block = new Block (data, new CID (hash))
82
+ const cid = new CID (multihash)
83
+ const block = new Block (data, cid)
82
84
83
85
// create a service
84
86
const bs = new BlockService (repo)
85
87
86
88
// add the block, then retrieve it
87
89
bs .put (block, (err ) => {
88
- if (err) throw err
89
- bs .get (block .cid , (err , b ) => {
90
- if (err) throw err
90
+ if (err) {
91
+ throw err
92
+ }
93
+ bs .get (cid, (err , b ) => {
94
+ if (err) {
95
+ throw err
96
+ }
91
97
console .log (block .data .toString () === b .data .toString ())
92
98
// => true
93
99
})
You can’t perform that action at this time.
0 commit comments