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

Commit 461c500

Browse files
committed
Output directories in Exporter.
1 parent 41ef542 commit 461c500

File tree

3 files changed

+11
-23
lines changed

3 files changed

+11
-23
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"block-stream2": "^1.1.0",
5757
"bs58": "^3.0.0",
5858
"debug": "^2.2.0",
59-
"field-trip": "0.0.2",
59+
"field-trip": "0.0.3",
6060
"ipfs-merkle-dag": "^0.5.0",
6161
"ipfs-unixfs": "^0.1.0",
6262
"is-ipfs": "^0.2.0",

src/exporter.js

+4-18
Original file line numberDiff line numberDiff line change
@@ -91,32 +91,18 @@ function Exporter (hash, dagService, options) {
9191

9292
// Logic to export a unixfs directory.
9393
let dirExporter = (node, name, add, done) => {
94-
let init
95-
9694
if (!add) throw new Error('add must be set')
9795
if (!done) throw new Error('done must be set')
9896

99-
var rs = new Readable()
97+
this.push({content: null, path: name})
10098

101-
// Directory has no links
102-
if (node.links.length === 0) {
103-
init = false
104-
rs._read = () => {
105-
if (init) {
106-
return
107-
}
108-
init = true
109-
rs.push(node.data)
110-
rs.push(null)
111-
}
112-
this.push({content: null, path: name})
113-
done()
114-
} else {
99+
// Directory has links
100+
if (node.links.length > 0) {
115101
node.links.forEach((link) => {
116102
add({ path: pathj.join(name, link.name), hash: link.hash })
117103
})
118-
done()
119104
}
105+
done()
120106
}
121107

122108
// Traverse the DAG asynchronously

test/test-exporter.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,12 @@ module.exports = function (repo) {
8787
expect(err).to.not.exist
8888
})
8989
testExport.pipe(concat((files) => {
90-
expect(files[0].path).to.equal('QmWChcSFMNcFkfeJtNd8Yru1rE6PhtCRfewi1tMwjkwKjN/200Bytes.txt')
91-
expect(files[1].path).to.equal('QmWChcSFMNcFkfeJtNd8Yru1rE6PhtCRfewi1tMwjkwKjN/dir-another')
92-
expect(files[2].path).to.equal('QmWChcSFMNcFkfeJtNd8Yru1rE6PhtCRfewi1tMwjkwKjN/level-1/200Bytes.txt')
93-
expect(files[3].path).to.equal('QmWChcSFMNcFkfeJtNd8Yru1rE6PhtCRfewi1tMwjkwKjN/level-1/level-2')
90+
expect(files[0].path).to.equal('QmWChcSFMNcFkfeJtNd8Yru1rE6PhtCRfewi1tMwjkwKjN')
91+
expect(files[1].path).to.equal('QmWChcSFMNcFkfeJtNd8Yru1rE6PhtCRfewi1tMwjkwKjN/200Bytes.txt')
92+
expect(files[2].path).to.equal('QmWChcSFMNcFkfeJtNd8Yru1rE6PhtCRfewi1tMwjkwKjN/dir-another')
93+
expect(files[3].path).to.equal('QmWChcSFMNcFkfeJtNd8Yru1rE6PhtCRfewi1tMwjkwKjN/level-1')
94+
expect(files[4].path).to.equal('QmWChcSFMNcFkfeJtNd8Yru1rE6PhtCRfewi1tMwjkwKjN/level-1/200Bytes.txt')
95+
expect(files[5].path).to.equal('QmWChcSFMNcFkfeJtNd8Yru1rE6PhtCRfewi1tMwjkwKjN/level-1/level-2')
9496
done()
9597
}))
9698
})

0 commit comments

Comments
 (0)