forked from ipfs-inactive/js-ipfs-http-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstat.js
41 lines (35 loc) · 936 Bytes
/
stat.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
'use strict'
const promisify = require('promisify-es6')
const _ = require('lodash')
const streamToValue = require('../utils/stream-to-value')
const transform = function (res, callback) {
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
})
})
}
module.exports = (send) => {
return promisify((args, opts, callback) => {
if (typeof (opts) === 'function') {
callback = opts
opts = {}
}
opts = _.mapKeys(opts, (v, k) => _.kebabCase(k))
send.andTransform({
path: 'files/stat',
args: args,
qs: opts
}, transform, callback)
})
}