Skip to content
This repository was archived by the owner on Aug 11, 2021. It is now read-only.

Commit 11aead3

Browse files
committed
docs: update documentation
1 parent bbec147 commit 11aead3

File tree

2 files changed

+75
-73
lines changed

2 files changed

+75
-73
lines changed

API.md

Lines changed: 0 additions & 67 deletions
This file was deleted.

README.md

Lines changed: 75 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,17 @@ var repo = new IPFSRepo('example', { stores: Store })
7272
// create a block
7373
const block = new Block('hello world)
7474
console.log(block.data)
75-
console.log(block.key)
75+
console.log(block.key())
7676

7777
// create a service
7878
const bs = new BlockService(repo)
7979

8080
// 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) {
8386
console.log(block.data.toString() === b.data.toString())
8487
})
8588
})
@@ -118,10 +121,70 @@ the global namespace.
118121
<script src="https://unpkg.com/ipfs-block-service/dist/index.js"></script>
119122
```
120123

121-
You can find the [API documentation here](API.md)
124+
# API
122125

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.
125188

126189
## Contribute
127190

@@ -134,3 +197,9 @@ This repository falls under the IPFS [Code of Conduct](https://github.com/ipfs/c
134197
## License
135198

136199
[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

Comments
 (0)