diff --git a/package.json b/package.json index 8b24f6e..7fcac5a 100644 --- a/package.json +++ b/package.json @@ -56,7 +56,7 @@ "ipfs-multipart": "~0.1.0", "ipfs-unixfs": "~0.1.16", "ipfs-unixfs-importer": "~0.37.0", - "ipfs-unixfs-exporter": "~0.35.0", + "ipfs-unixfs-exporter": "~0.35.1", "ipld-dag-pb": "~0.15.0", "is-pull-stream": "~0.0.0", "is-stream": "^1.1.0", diff --git a/src/core/stat.js b/src/core/stat.js index 05416f4..8dc4c98 100644 --- a/src/core/stat.js +++ b/src/core/stat.js @@ -11,6 +11,7 @@ const pull = require('pull-stream/pull') const collect = require('pull-stream/sinks/collect') const asyncMap = require('pull-stream/throughs/async-map') const exporter = require('ipfs-unixfs-exporter') +const CID = require('cids') const log = require('debug')('ipfs:mfs:stat') const defaultOptions = { @@ -40,6 +41,18 @@ module.exports = (context) => { }), asyncMap((file, cb) => { + if (options.hash) { + return cb(null, { + hash: formatCid(new CID(file.hash), options.cidBase) + }) + } + + if (options.size) { + return cb(null, { + size: file.size + }) + } + loadNode(context, { cid: file.hash }, (err, result) => { @@ -51,18 +64,7 @@ module.exports = (context) => { node, cid } = result - if (options.hash) { - return cb(null, { - hash: formatCid(cid, options.cidBase) - }) - } else if (options.size) { - return cb(null, { - size: node.size - }) - } - const meta = unmarshal(node.data) - let blocks = node.links.length if (meta.type === 'file') {