@@ -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
┌─────────┐ ┌───────┐
@@ -42,6 +41,7 @@ backed by an [IPFS Repo][repo] as its datastore for blocks, and uses [Bitswap][b
42
41
- [ Example] ( #example )
43
42
- [ Browser: Browserify, Webpack, other bundlers] ( #browser-browserify-webpack-other-bundlers )
44
43
- [ Browser: ` <script> ` Tag] ( #browser-script-tag )
44
+ - [ API] ( #api )
45
45
- [ Contribute] ( #contribute )
46
46
- [ License] ( #license )
47
47
@@ -50,7 +50,7 @@ backed by an [IPFS Repo][repo] as its datastore for blocks, and uses [Bitswap][b
50
50
### npm
51
51
52
52
``` sh
53
- > npm i ipfs-block-service
53
+ > npm install ipfs-block-service
54
54
```
55
55
56
56
## Usage
@@ -68,48 +68,41 @@ const BlockService = require('ipfs-block-service')
68
68
const BlockService = require (' ipfs-block-service' )
69
69
const Block = require (' ipfs-block' )
70
70
const IPFSRepo = require (' ipfs-repo' ) // storage repo
71
- const Store = require (' interface-pull-blob-store' ) // in-memory store
72
71
73
72
// setup a repo
74
- var repo = new IPFSRepo (' example' , { stores : Store } )
73
+ const repo = new IPFSRepo (' example' )
75
74
76
75
// create a block
77
- const block = new Block (' hello world' )
78
- console .log (block .data )
79
- console .log (block .key ())
80
-
81
- // create a service
82
- const bs = new BlockService (repo)
83
-
84
- // add the block, then retrieve it
85
- bs .put ({
86
- block: block,
87
- cid: cid,
88
- }, function (err ) {
89
- bs .get (cid, function (err , b ) {
90
- console .log (block .data .toString () === b .data .toString ())
76
+ const data = new Buffer (' hello world' )
77
+ multihashing (data, ' sha2-256' , (err , multihash ) => {
78
+ if (err) {
79
+ throw err
80
+ }
81
+
82
+ const cid = new CID (multihash)
83
+ const block = new Block (data, cid)
84
+
85
+ // create a service
86
+ const bs = new BlockService (repo)
87
+
88
+ // add the block, then retrieve it
89
+ bs .put (block, (err ) => {
90
+ if (err) {
91
+ throw err
92
+ }
93
+ bs .get (cid, (err , b ) => {
94
+ if (err) {
95
+ throw err
96
+ }
97
+ console .log (block .data .toString () === b .data .toString ())
98
+ // => true
99
+ })
91
100
})
92
101
})
93
102
```
94
103
95
- outputs
96
-
97
- ```
98
- <Buffer 68 65 6c 6c 6f 20 77 61 72 6c 64>
99
-
100
- <Buffer 12 20 db 3c 15 23 3f f3 84 8f 42 fe 3b 74 78 90 90 5a 80 7e a6 ef 2b 6d 2f 3c 8b 2c b7 ae be 86 3c 4d>
101
-
102
- true
103
-
104
- ```
105
-
106
104
### Browser: Browserify, Webpack, other bundlers
107
105
108
- The code published to npm that gets loaded on require is in fact a ES5
109
- transpiled version with the right shims added. This means that you can require
110
- it and use with your favourite bundler without having to adjust asset management
111
- process.
112
-
113
106
``` JavaScript
114
107
var BlockService = require (' ipfs-block-service' )
115
108
```
@@ -125,70 +118,9 @@ the global namespace.
125
118
<script src =" https://unpkg.com/ipfs-block-service/dist/index.js" ></script >
126
119
```
127
120
128
- # API
129
-
130
- ``` js
131
- const BlockService = require (' ipfs-block-service' )
132
- ```
133
-
134
- ### ` new BlockService(repo) `
135
-
136
- - ` repo: Repo `
137
-
138
- Creates a new block service backed by [ IPFS Repo] [ repo ] ` repo ` for storage.
139
-
140
- ### ` goOnline(bitswap) `
141
-
142
- - ` bitswap: Bitswap `
143
-
144
- Add a bitswap instance that communicates with the network to retreive blocks
145
- that are not in the local store.
146
-
147
- If the node is online all requests for blocks first check locally and
148
- afterwards ask the network for the blocks.
121
+ ## API
149
122
150
- ### ` goOffline() `
151
-
152
- Remove the bitswap instance and fall back to offline mode.
153
-
154
- ### ` isOnline() `
155
-
156
- Returns a ` Boolean ` indicating if the block service is online or not.
157
-
158
- ### ` put(blockAndCID, callback) `
159
-
160
- - ` blockAndCID: { block: block, cid: cid } `
161
- - ` callback: Function `
162
-
163
- Asynchronously adds a block instance to the underlying repo.
164
-
165
- ### ` putStream() `
166
-
167
- Returns a through pull-stream, which ` blockAndCID ` s can be written to, and
168
- that emits the meta data about the written block.
169
-
170
- ### ` get(cid [, extension], callback) `
171
-
172
- - ` cid: CID `
173
- - ` extension: String ` , defaults to 'data'
174
- - ` callback: Function `
175
-
176
- Asynchronously returns the block whose content multihash matches ` multihash ` .
177
-
178
- ### ` getStream(cid [, extension]) `
179
-
180
- - ` cid: CID `
181
- - ` extension: String ` , defaults to 'data'
182
-
183
- Returns a source pull-stream, which emits the requested block.
184
-
185
- ### ` delete(cids, [, extension], callback) `
186
-
187
- - ` cids: CID | []CID `
188
- - ` extension: String ` , defaults to 'data' - ` extension: String ` , defaults to 'data'
189
- - ` callback: Function `
190
-
191
- Deletes all blocks referenced by multihashes.
123
+ See https://ipfs.github.io/js-ipfs-block-service
192
124
193
125
## Contribute
194
126
@@ -205,5 +137,3 @@ This repository falls under the IPFS [Code of Conduct](https://github.com/ipfs/c
205
137
[ ipfs ] : https://ipfs.io
206
138
[ bitswap ] : https://github.com/ipfs/specs/tree/master/bitswap
207
139
[ repo ] : https://github.com/ipfs/specs/tree/master/repo
208
-
209
-
0 commit comments