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

exporter maxDepth #197

Merged
merged 10 commits into from
Nov 12, 2017
2 changes: 1 addition & 1 deletion src/exporter/dir-flat.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const cat = require('pull-cat')
// Logic to export a unixfs directory.
module.exports = dirExporter

function dirExporter (node, name, path, pathRest, resolve, dag, parent, depth) {
function dirExporter (node, name, path, pathRest, resolve, size, dag, parent, depth) {
const accepts = pathRest[0]

const dir = {
Expand Down
2 changes: 1 addition & 1 deletion src/exporter/dir-hamt-sharded.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const cleanHash = require('./clean-multihash')
// Logic to export a unixfs directory.
module.exports = shardedDirExporter

function shardedDirExporter (node, name, path, pathRest, resolve, dag, parent, depth) {
function shardedDirExporter (node, name, path, pathRest, resolve, size, dag, parent, depth) {
let dir
if (!parent || (parent.path !== path)) {
dir = {
Expand Down
4 changes: 2 additions & 2 deletions src/exporter/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const pull = require('pull-stream')
const paramap = require('pull-paramap')

// Logic to export a single (possibly chunked) unixfs file.
module.exports = (node, name, path, pathRest, resolve, dag, parent, depth) => {
module.exports = (node, name, path, pathRest, resolve, size, dag, parent, depth) => {
function getData (node) {
try {
const file = UnixFS.unmarshal(node.data)
Expand Down Expand Up @@ -43,7 +43,7 @@ module.exports = (node, name, path, pathRest, resolve, dag, parent, depth) => {
name: name,
path: path,
hash: node.multihash,
size: file.fileSize(),
size: size || file.fileSize(),
type: 'file'
}])
}
2 changes: 1 addition & 1 deletion src/exporter/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const CID = require('cids')
const pull = require('pull-stream')

module.exports = (node, name, path, pathRest, resolve, dag, parent, depth) => {
module.exports = (node, name, path, pathRest, resolve, size, dag, parent, depth) => {
let newNode
if (pathRest.length) {
const pathElem = pathRest[0]
Expand Down
6 changes: 3 additions & 3 deletions src/exporter/resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,17 @@ function createResolver (dag, options, depth, parent) {
)

function resolveItem (node, item) {
return resolve(node, item.name, item.path, item.pathRest, dag, item.parent || parent, item.depth)
return resolve(node, item.name, item.path, item.pathRest, item.size, dag, item.parent || parent, item.depth)
}

function resolve (node, name, path, pathRest, dag, parentNode, depth) {
function resolve (node, name, path, pathRest, size, dag, parentNode, depth) {
const type = typeOf(node)
const nodeResolver = resolvers[type]
if (!nodeResolver) {
return pull.error(new Error('Unkown node type ' + type))
}
const resolveDeep = createResolver(dag, options, depth, node)
return nodeResolver(node, name, path, pathRest, resolveDeep, dag, parentNode, depth)
return nodeResolver(node, name, path, pathRest, resolveDeep, size, dag, parentNode, depth)
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/builder-dir-sharding.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ module.exports = (repo) => {
expect(nodes[0].path).to.be.eql(expectedHash)
expect(mh.toB58String(nodes[0].hash)).to.be.eql(expectedHash)
expect(nodes[1].path).to.be.eql(expectedHash + '/b')
expect(nodes[1].size).to.be.eql(21)
expect(nodes[1].size).to.be.eql(29)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this need to change if the test is the same?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had to change this for ls because go-ipfs reports the size as reported by the link, not the what we get from the file.size accessor... Still have to investigate which one is the correct one. Any clues on why these values differ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, I believe that was added for ipfs.add and it seems it also made it to .ls. LGTM then :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

pull(
nodes[1].content,
pull.collect(collected)
Expand Down