@@ -72,14 +72,17 @@ var repo = new IPFSRepo('example', { stores: Store })
72
72
// create a block
73
73
const block = new Block(' hello world)
74
74
console .log (block .data )
75
- console .log (block .key )
75
+ console .log (block .key () )
76
76
77
77
// create a service
78
78
const bs = new BlockService (repo)
79
79
80
80
// add the block, then retrieve it
81
- bs .addBlock (block, function (err ) {
82
- bs .getBlock (block .key , function (err , b ) {
81
+ bs .put ({
82
+ block: block,
83
+ cid: cid,
84
+ }, function (err ) {
85
+ bs .get (cid, function (err , b ) {
83
86
console .log (block .data .toString () === b .data .toString ())
84
87
})
85
88
})
@@ -118,10 +121,70 @@ the global namespace.
118
121
<script src =" https://unpkg.com/ipfs-block-service/dist/index.js" ></script >
119
122
```
120
123
121
- You can find the [ API documentation here ] ( API.md )
124
+ # API
122
125
123
- [ ipfs ] : https://ipfs.io
124
- [ bitswap ] : https://github.com/ipfs/specs/tree/master/bitswap
126
+ ``` js
127
+ const BlockService = require (' ipfs-block-service' )
128
+ ```
129
+
130
+ ### ` new BlockService(repo) `
131
+
132
+ - ` repo: Repo `
133
+
134
+ Creates a new block service backed by [ IPFS Repo] [ repo ] ` repo ` for storage.
135
+
136
+ ### ` goOnline(bitswap) `
137
+
138
+ - ` bitswap: Bitswap `
139
+
140
+ Add a bitswap instance that communicates with the network to retreive blocks
141
+ that are not in the local store.
142
+
143
+ If the node is online all requests for blocks first check locally and
144
+ afterwards ask the network for the blocks.
145
+
146
+ ### ` goOffline() `
147
+
148
+ Remove the bitswap instance and fall back to offline mode.
149
+
150
+ ### ` isOnline() `
151
+
152
+ Returns a ` Boolean ` indicating if the block service is online or not.
153
+
154
+ ### ` put(blockAndCID, callback) `
155
+
156
+ - ` blockAndCID: { block: block, cid: cid } `
157
+ - ` callback: Function `
158
+
159
+ Asynchronously adds a block instance to the underlying repo.
160
+
161
+ ### ` putStream() `
162
+
163
+ Returns a through pull-stream, which ` blockAndCID ` s can be written to, and
164
+ that emits the meta data about the written block.
165
+
166
+ ### ` get(cid [, extension], callback) `
167
+
168
+ - ` cid: CID `
169
+ - ` extension: String ` , defaults to 'data'
170
+ - ` callback: Function `
171
+
172
+ Asynchronously returns the block whose content multihash matches ` multihash ` .
173
+
174
+ ### ` getStream(cid [, extension]) `
175
+
176
+ - ` cid: CID `
177
+ - ` extension: String ` , defaults to 'data'
178
+
179
+ Returns a source pull-stream, which emits the requested block.
180
+
181
+ ### ` delete(cids, [, extension], callback) `
182
+
183
+ - ` cids: CID | []CID `
184
+ - ` extension: String ` , defaults to 'data' - ` extension: String ` , defaults to 'data'
185
+ - ` callback: Function `
186
+
187
+ Deletes all blocks referenced by multihashes.
125
188
126
189
## Contribute
127
190
@@ -134,3 +197,9 @@ This repository falls under the IPFS [Code of Conduct](https://github.com/ipfs/c
134
197
## License
135
198
136
199
[ MIT] ( LICENSE )
200
+
201
+ [ ipfs ] : https://ipfs.io
202
+ [ bitswap ] : https://github.com/ipfs/specs/tree/master/bitswap
203
+ [ repo ] : https://github.com/ipfs/specs/tree/master/repo
204
+
205
+
0 commit comments