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

Commit 43503d4

Browse files
fix(exporter): add some parallel fetching of blocks where possible
1 parent 9540d73 commit 43503d4

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
"is-ipfs": "^0.2.0",
5555
"multihashes": "^0.2.2",
5656
"pull-block": "^1.0.2",
57+
"pull-paramap": "^1.1.6",
5758
"pull-pushable": "^2.0.1",
5859
"pull-stream": "^3.4.5",
5960
"pull-traverse": "^1.0.3",
@@ -70,4 +71,4 @@
7071
"jbenet <juan@benet.ai>",
7172
"nginnever <ginneversource@gmail.com>"
7273
]
73-
}
74+
}

src/exporters/dir.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const path = require('path')
44
const pull = require('pull-stream')
5+
const paramap = require('pull-paramap')
56

67
const fileExporter = require('./file')
78
const switchType = require('../util').switchType
@@ -14,15 +15,17 @@ module.exports = (node, name, dagService) => {
1415
path: path.join(name, link.name),
1516
hash: link.hash
1617
})),
17-
pull.map((item) => pull(
18-
dagService.getStream(item.hash),
19-
pull.map((n) => switchType(
18+
paramap((item, cb) => dagService.get(item.hash, (err, n) => {
19+
if (err) {
20+
return cb(err)
21+
}
22+
23+
cb(null, switchType(
2024
n,
2125
() => pull.values([item]),
2226
() => fileExporter(n, item.path, dagService)
23-
)),
24-
pull.flatten()
25-
)),
27+
))
28+
})),
2629
pull.flatten()
2730
)
2831
}

src/exporters/file.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
const traverse = require('pull-traverse')
44
const UnixFS = require('ipfs-unixfs')
55
const pull = require('pull-stream')
6+
const paramap = require('pull-paramap')
67

78
// Logic to export a single (possibly chunked) unixfs file.
89
module.exports = (node, name, ds) => {
@@ -18,8 +19,7 @@ module.exports = (node, name, ds) => {
1819
function visitor (node) {
1920
return pull(
2021
pull.values(node.links),
21-
pull.map((link) => ds.getStream(link.hash)),
22-
pull.flatten()
22+
paramap((link, cb) => ds.get(link.hash, cb))
2323
)
2424
}
2525

0 commit comments

Comments
 (0)