From 4dba14c1a5b2fbe69dfa0eef5bb21ac480aeba49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Mur=C3=A9?= Date: Mon, 19 Feb 2018 16:10:28 +0100 Subject: [PATCH 1/2] add support for ipfs files stat --with-local --- src/files/stat.js | 9 ++++++++- test/files.spec.js | 5 ++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/files/stat.js b/src/files/stat.js index d53da0dab..94f18d541 100644 --- a/src/files/stat.js +++ b/src/files/stat.js @@ -1,6 +1,7 @@ 'use strict' const promisify = require('promisify-es6') +const _ = require('lodash') const transform = function (res, callback) { callback(null, { @@ -8,7 +9,10 @@ const transform = function (res, callback) { blocks: res.Blocks, size: res.Size, hash: res.Hash, - cumulativeSize: res.CumulativeSize + cumulativeSize: res.CumulativeSize, + withLocality: res.WithLocality || false, + local: res.Local || undefined, + sizeLocal: res.SizeLocal || undefined }) } @@ -18,6 +22,9 @@ module.exports = (send) => { callback = opts opts = {} } + + opts = _.mapKeys(opts, (v, k) => _.kebabCase(k)) + send.andTransform({ path: 'files/stat', args: args, diff --git a/test/files.spec.js b/test/files.spec.js index 41c5bc1a8..c05aa23a1 100644 --- a/test/files.spec.js +++ b/test/files.spec.js @@ -282,7 +282,10 @@ describe('.files (the MFS API part)', function () { size: 12, cumulativeSize: 20, blocks: 0, - type: 'file' + type: 'file', + withLocality: false, + local: undefined, + sizeLocal: undefined }) done() From 490bee180bad8e9e9facb3f7027d4036a525e1d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Mur=C3=A9?= Date: Sat, 10 Mar 2018 16:11:37 +0100 Subject: [PATCH 2/2] files stat: don't forget to unwrap the stream --- src/files/stat.js | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/files/stat.js b/src/files/stat.js index 94f18d541..804865ba0 100644 --- a/src/files/stat.js +++ b/src/files/stat.js @@ -2,17 +2,24 @@ const promisify = require('promisify-es6') const _ = require('lodash') +const streamToValue = require('../utils/stream-to-value') const transform = function (res, callback) { - callback(null, { - type: res.Type, - blocks: res.Blocks, - size: res.Size, - hash: res.Hash, - cumulativeSize: res.CumulativeSize, - withLocality: res.WithLocality || false, - local: res.Local || undefined, - sizeLocal: res.SizeLocal || undefined + return streamToValue(res, (err, data) => { + if (err) { + return callback(err) + } + + callback(null, { + type: data[0].Type, + blocks: data[0].Blocks, + size: data[0].Size, + hash: data[0].Hash, + cumulativeSize: data[0].CumulativeSize, + withLocality: data[0].WithLocality || false, + local: data[0].Local || null, + sizeLocal: data[0].SizeLocal || null + }) }) }