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

Commit 69c0d04

Browse files
pgtedaviddias
authored andcommitted
fix: exporter: recurse correctly into subdirs (#136)
* fix: exporter: recurse correctly into subdirs * fix: exporter: also yielding dir before recursing
1 parent bcd0482 commit 69c0d04

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
"lodash": "^4.17.4",
6464
"multihashes": "^0.3.2",
6565
"pull-batch": "^1.0.0",
66+
"pull-cat": "^1.1.11",
6667
"pull-block": "^1.1.0",
6768
"pull-pair": "^1.1.0",
6869
"pull-paramap": "^1.2.1",
@@ -84,4 +85,4 @@
8485
"jbenet <[email protected]>",
8586
"nginnever <[email protected]>"
8687
]
87-
}
88+
}

src/exporter/dir.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@ const path = require('path')
44
const pull = require('pull-stream')
55
const paramap = require('pull-paramap')
66
const CID = require('cids')
7+
const cat = require('pull-cat')
78

89
const fileExporter = require('./file')
910
const switchType = require('../util').switchType
1011

1112
// Logic to export a unixfs directory.
12-
module.exports = (node, name, ipldResolver) => {
13+
module.exports = dirExporter
14+
15+
function dirExporter (node, name, ipldResolver) {
1316
// The algorithm below is as follows
1417
//
1518
// 1. Take all links from a given directory node
@@ -20,6 +23,7 @@ module.exports = (node, name, ipldResolver) => {
2023
// - `directory`: return node
2124
// - `file`: use the fileExporter to load and return the file
2225
// 4. Flatten
26+
2327
return pull(
2428
pull.values(node.links),
2529
pull.map((link) => ({
@@ -31,9 +35,14 @@ module.exports = (node, name, ipldResolver) => {
3135
return cb(err)
3236
}
3337

38+
const dir = {
39+
path: item.path,
40+
size: item.size
41+
}
42+
3443
cb(null, switchType(
3544
n,
36-
() => pull.values([item]),
45+
() => cat([pull.values([dir]), dirExporter(n, item.path, ipldResolver)]),
3746
() => fileExporter(n, item.path, ipldResolver)
3847
))
3948
})),

0 commit comments

Comments
 (0)