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

Commit

Permalink
feat: pass CID directly into bitswap
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddias committed Dec 23, 2016
1 parent 673ddf8 commit f0c3e42
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"chai": "^3.5.0",
"fs-pull-blob-store": "^0.4.1",
"idb-pull-blob-store": "^0.5.1",
"ipfs-block": "^0.5.3",
"ipfs-block": "^0.5.4",
"ipfs-repo": "^0.11.2",
"lodash": "^4.17.2",
"ncp": "^2.0.0",
Expand All @@ -64,4 +64,4 @@
"npmcdn-to-unpkg-bot <npmcdn-to-unpkg-bot@users.noreply.github.com>",
"wanderer <mjbecze@gmail.com>"
]
}
}
27 changes: 11 additions & 16 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,24 +44,19 @@ module.exports = class BlockService {
}

putStream () {
let ps
if (this.isOnline()) {
// NOTE: This will have to change in order for bitswap
// to understand CID
ps = this._bitswap.putStream()
return this._bitswap.putStream()
} else {
ps = this._repo.blockstore.putStream()
return pull(
pull.map((blockAndCID) => {
return {
data: blockAndCID.block.data,
key: blockAndCID.cid.multihash
}
}),
this._repo.blockstore.putStream()
)
}

return pull(
pull.map((blockAndCID) => {
return {
data: blockAndCID.block.data,
key: blockAndCID.cid.multihash
}
}),
ps
)
}

get (cid, callback) {
Expand All @@ -78,7 +73,7 @@ module.exports = class BlockService {

getStream (cid) {
if (this.isOnline()) {
return this._bitswap.getStream(cid.multihash)
return this._bitswap.getStream(cid)
}

return this._repo.blockstore.getStream(cid.multihash)
Expand Down

0 comments on commit f0c3e42

Please sign in to comment.