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

add support for ipfs files stat --with-local #695

Merged
merged 2 commits into from
Mar 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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