|
1 | 1 | 'use strict' |
2 | 2 |
|
3 | | -const traverse = require('pull-traverse') |
4 | 3 | const pull = require('pull-stream') |
5 | 4 | const CID = require('cids') |
6 | 5 | const isIPFS = require('is-ipfs') |
7 | 6 |
|
8 | | -const util = require('./../util') |
9 | | -const switchType = util.switchType |
10 | | -const cleanMultihash = util.cleanMultihash |
| 7 | +const resolve = require('./resolve').resolve |
| 8 | +const cleanMultihash = require('./clean-multihash') |
11 | 9 |
|
12 | | -const dirExporter = require('./dir') |
13 | | -const fileExporter = require('./file') |
14 | | - |
15 | | -module.exports = (hash, ipldResolver, options) => { |
| 10 | +module.exports = (hash, ipldResolver) => { |
16 | 11 | if (!isIPFS.multihash(hash)) { |
17 | 12 | return pull.error(new Error('not valid multihash')) |
18 | 13 | } |
19 | 14 |
|
20 | 15 | hash = cleanMultihash(hash) |
21 | | - options = options || {} |
22 | | - |
23 | | - function visitor (item) { |
24 | | - if (!item.hash) { |
25 | | - // having no hash means that this visitor got a file object |
26 | | - // which needs no further resolving. |
27 | | - // No further resolving means that the visitor does not |
28 | | - // need to do anyting else, so he's returning |
29 | | - // an empty stream |
30 | | - |
31 | | - // TODO: perhaps change the pull streams construct. |
32 | | - // Instead of traversing with a visitor, consider recursing. |
33 | | - return pull.empty() |
34 | | - } |
35 | | - return pull( |
36 | | - ipldResolver.getStream(new CID(item.hash)), |
37 | | - pull.map((result) => result.value), |
38 | | - pull.map((node) => switchType( |
39 | | - node, |
40 | | - () => dirExporter(node, item.path, ipldResolver), |
41 | | - () => fileExporter(node, item.path, ipldResolver) |
42 | | - )), |
43 | | - pull.flatten() |
44 | | - ) |
45 | | - } |
46 | 16 |
|
47 | | - // Traverse the DAG |
48 | 17 | return pull( |
49 | 18 | ipldResolver.getStream(new CID(hash)), |
50 | 19 | pull.map((result) => result.value), |
51 | | - pull.map((node) => switchType( |
52 | | - node, |
53 | | - () => traverse.widthFirst({path: hash, hash}, visitor), |
54 | | - () => fileExporter(node, hash, ipldResolver) |
55 | | - )), |
| 20 | + pull.map((node) => resolve(node, hash, ipldResolver)), |
56 | 21 | pull.flatten() |
57 | 22 | ) |
58 | 23 | } |
0 commit comments