-
Notifications
You must be signed in to change notification settings - Fork 47
[WIP] Pull streams #25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ sudo: false | |
language: node_js | ||
node_js: | ||
- 4 | ||
- 5 | ||
- stable | ||
|
||
# Make sure we have new NPM. | ||
before_install: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,52 +6,61 @@ | |
|
||
- `id: PeerId`, the id of the local instance. | ||
- `libp2p: Libp2p`, instance of the local network stack. | ||
- `datastore: Datastore`, instance of the local database (`IpfsRepo.datastore`) | ||
- `blockstore: Datastore`, instance of the local database (`IpfsRepo.blockstore`) | ||
|
||
Create a new instance. | ||
|
||
### `getBlock(key, cb)` | ||
|
||
- `key: Multihash` | ||
- `cb: Function` | ||
### `getStream(key)` | ||
|
||
Fetch a single block. | ||
- `key: Multihash|Array` | ||
|
||
> Note: This is safe guarded so that the network is not asked | ||
> for blocks that are in the local `datastore`. | ||
Returns a source `pull-stream`. Values emitted are the received blocks. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this going to return several blocks for one key? Seems that there is a need for get(key), get(keys), getStream(keys) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed, it now takes an array, or a single key. |
||
|
||
### `getBlocks(keys, cb)` | ||
|
||
- `keys: []Multihash` | ||
- `cb: Function` | ||
Example: | ||
|
||
Fetch multiple blocks. The `cb` is called with a result object of the form | ||
```js | ||
{ | ||
[key1]: {error: errorOrUndefined, block: blockOrUndefined}, | ||
[key2]: {error: errorOrUndefined, block: blockOrUndefined}, | ||
... | ||
} | ||
// Single block | ||
pull( | ||
bitswap.getStream(key), | ||
pull.collect((err, blocks) => { | ||
// blocks === [block] | ||
}) | ||
) | ||
|
||
// Many blocks | ||
pull( | ||
bitswap.getStream([key1, key2, key3]), | ||
pull.collect((err, blocks) => { | ||
// blocks === [block1, block2, block3] | ||
}) | ||
) | ||
``` | ||
|
||
Where `key<i>` is the multihash of the block. | ||
|
||
### `unwantBlocks(keys)` | ||
> Note: This is safe guarded so that the network is not asked | ||
> for blocks that are in the local `datastore`. | ||
|
||
|
||
- `keys: []Multihash` | ||
### `unwant(keys)` | ||
|
||
- `keys: Mutlihash|[]Multihash` | ||
|
||
Cancel previously requested keys, forcefully. That means they are removed from the | ||
wantlist independent of how many other resources requested these keys. Callbacks | ||
attached to `getBlock` are errored with `Error('manual unwant: key')`. | ||
|
||
### `cancelWants(keys)` | ||
|
||
- `keys: []Multihash` | ||
- `keys: Multihash|[]Multihash` | ||
|
||
Cancel previously requested keys. | ||
|
||
### `putStream()` | ||
|
||
Returns a duplex `pull-stream` that emits an object `{key: Multihash}` for every written block when it was stored. | ||
|
||
### `hasBlock(block, cb)` | ||
### `put(block, cb)` | ||
|
||
- `block: IpfsBlock` | ||
- `cb: Function` | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,40 +33,43 @@ | |
}, | ||
"homepage": "https://github.com/ipfs/js-ipfs-bitswap#readme", | ||
"devDependencies": { | ||
"abstract-blob-store": "^3.2.0", | ||
"aegir": "^8.0.1", | ||
"buffer-loader": "0.0.1", | ||
"chai": "^3.5.0", | ||
"fs-blob-store": "^5.2.1", | ||
"idb-plus-blob-store": "^1.1.2", | ||
"ipfs-repo": "^0.8.0", | ||
"libp2p-ipfs": "^0.12.0", | ||
"lodash": "^4.13.1", | ||
"fs-pull-blob-store": "^0.3.0", | ||
"idb-pull-blob-store": "^0.4.0", | ||
"interface-pull-blob-store": "^0.5.0", | ||
"ipfs-repo": "^0.9.0", | ||
"libp2p-ipfs": "^0.13.0", | ||
"lodash": "^4.15.0", | ||
"multiaddr": "^2.0.3", | ||
"ncp": "^2.0.0", | ||
"peer-book": "^0.3.0", | ||
"peer-id": "^0.7.0", | ||
"peer-info": "^0.7.1", | ||
"rimraf": "^2.5.2", | ||
"rimraf": "^2.5.4", | ||
"safe-buffer": "^5.0.1" | ||
}, | ||
"dependencies": { | ||
"async": "^2.0.0-rc.5", | ||
"bl": "^1.1.2", | ||
"async": "^2.0.1", | ||
"debug": "^2.2.0", | ||
"heap": "^0.2.6", | ||
"highland": "^3.0.0-beta.1", | ||
"ipfs-block": "^0.3.0", | ||
"length-prefixed-stream": "^1.5.0", | ||
"lodash.isequalwith": "^4.2.0", | ||
"lodash.isequalwith": "^4.4.0", | ||
"lodash.isundefined": "^3.0.1", | ||
"multihashes": "^0.2.2", | ||
"protocol-buffers": "^3.1.6" | ||
"protocol-buffers": "^3.1.6", | ||
"pull-defer": "^0.2.2", | ||
"pull-generate": "^2.2.0", | ||
"pull-length-prefixed": "^1.2.0", | ||
"pull-paramap": "^1.1.6", | ||
"pull-pushable": "^2.0.1", | ||
"pull-stream": "^3.4.5" | ||
}, | ||
"contributors": [ | ||
"David Dias <[email protected]>", | ||
"Richard Littauer <[email protected]>", | ||
"Stephen Whitmore <[email protected]>", | ||
"dignifiedquire <[email protected]>" | ||
] | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add Node.js 5 too