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

Commit

Permalink
fix(exporter): add some parallel fetching of blocks where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed Sep 16, 2016
1 parent 9540d73 commit 43503d4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"is-ipfs": "^0.2.0",
"multihashes": "^0.2.2",
"pull-block": "^1.0.2",
"pull-paramap": "^1.1.6",
"pull-pushable": "^2.0.1",
"pull-stream": "^3.4.5",
"pull-traverse": "^1.0.3",
Expand All @@ -70,4 +71,4 @@
"jbenet <[email protected]>",
"nginnever <[email protected]>"
]
}
}
15 changes: 9 additions & 6 deletions src/exporters/dir.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const path = require('path')
const pull = require('pull-stream')
const paramap = require('pull-paramap')

const fileExporter = require('./file')
const switchType = require('../util').switchType
Expand All @@ -14,15 +15,17 @@ module.exports = (node, name, dagService) => {
path: path.join(name, link.name),
hash: link.hash
})),
pull.map((item) => pull(
dagService.getStream(item.hash),
pull.map((n) => switchType(
paramap((item, cb) => dagService.get(item.hash, (err, n) => {
if (err) {
return cb(err)
}

cb(null, switchType(
n,
() => pull.values([item]),
() => fileExporter(n, item.path, dagService)
)),
pull.flatten()
)),
))
})),
pull.flatten()
)
}
4 changes: 2 additions & 2 deletions src/exporters/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const traverse = require('pull-traverse')
const UnixFS = require('ipfs-unixfs')
const pull = require('pull-stream')
const paramap = require('pull-paramap')

// Logic to export a single (possibly chunked) unixfs file.
module.exports = (node, name, ds) => {
Expand All @@ -18,8 +19,7 @@ module.exports = (node, name, ds) => {
function visitor (node) {
return pull(
pull.values(node.links),
pull.map((link) => ds.getStream(link.hash)),
pull.flatten()
paramap((link, cb) => ds.get(link.hash, cb))
)
}

Expand Down

0 comments on commit 43503d4

Please sign in to comment.