ipfs-api
Version:
A client library for the IPFS HTTP API
30 lines (24 loc) • 598 B
JavaScript
const promisify = require('promisify-es6')
const streamToValue = require('../utils/stream-to-value')
const transformChunk = require('./bw-util')
const transform = (res, callback) => {
return streamToValue(res, (err, data) => {
if (err) {
return callback(err)
}
callback(null, transformChunk(data[0]))
})
}
module.exports = (send) => {
return promisify((opts, callback) => {
if (typeof (opts) === 'function') {
callback = opts
opts = {}
}
send.andTransform({
path: 'stats/bw',
qs: opts
}, transform, callback)
})
}