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

Commit

Permalink
feat: add support for ipfs files stat --with-local (#695)
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelMure authored and daviddias committed Mar 14, 2018
1 parent a10e3d5 commit b08f21a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
26 changes: 20 additions & 6 deletions src/files/stat.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
'use strict'

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
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
})
})
}

Expand All @@ -18,6 +29,9 @@ module.exports = (send) => {
callback = opts
opts = {}
}

opts = _.mapKeys(opts, (v, k) => _.kebabCase(k))

send.andTransform({
path: 'files/stat',
args: args,
Expand Down
5 changes: 4 additions & 1 deletion test/files.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit b08f21a

Please sign in to comment.