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

Commit

Permalink
fix: exporter: recurse correctly into subdirs (#136)
Browse files Browse the repository at this point in the history
* fix: exporter: recurse correctly into subdirs

* fix: exporter: also yielding dir before recursing
  • Loading branch information
pgte authored and daviddias committed Feb 2, 2017
1 parent bcd0482 commit 69c0d04
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"lodash": "^4.17.4",
"multihashes": "^0.3.2",
"pull-batch": "^1.0.0",
"pull-cat": "^1.1.11",
"pull-block": "^1.1.0",
"pull-pair": "^1.1.0",
"pull-paramap": "^1.2.1",
Expand All @@ -84,4 +85,4 @@
"jbenet <[email protected]>",
"nginnever <[email protected]>"
]
}
}
13 changes: 11 additions & 2 deletions src/exporter/dir.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ const path = require('path')
const pull = require('pull-stream')
const paramap = require('pull-paramap')
const CID = require('cids')
const cat = require('pull-cat')

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

// Logic to export a unixfs directory.
module.exports = (node, name, ipldResolver) => {
module.exports = dirExporter

function dirExporter (node, name, ipldResolver) {
// The algorithm below is as follows
//
// 1. Take all links from a given directory node
Expand All @@ -20,6 +23,7 @@ module.exports = (node, name, ipldResolver) => {
// - `directory`: return node
// - `file`: use the fileExporter to load and return the file
// 4. Flatten

return pull(
pull.values(node.links),
pull.map((link) => ({
Expand All @@ -31,9 +35,14 @@ module.exports = (node, name, ipldResolver) => {
return cb(err)
}

const dir = {
path: item.path,
size: item.size
}

cb(null, switchType(
n,
() => pull.values([item]),
() => cat([pull.values([dir]), dirExporter(n, item.path, ipldResolver)]),
() => fileExporter(n, item.path, ipldResolver)
))
})),
Expand Down

0 comments on commit 69c0d04

Please sign in to comment.