ipfs-http-client
Version:
A client library for the IPFS HTTP API
30 lines (26 loc) • 827 B
JavaScript
import { configure } from '../lib/configure.js'
import { toUrlSearchParams } from '../lib/to-url-search-params.js'
/**
* @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions
* @typedef {import('ipfs-core-types/src/stats').API<HTTPClientExtraOptions>} StatsAPI
*/
export const createBw = configure(api => {
/**
* @type {StatsAPI["bw"]}
*/
async function * bw (options = {}) {
const res = await api.post('stats/bw', {
signal: options.signal,
searchParams: toUrlSearchParams(options),
headers: options.headers,
transform: (stats) => ({
totalIn: BigInt(stats.TotalIn),
totalOut: BigInt(stats.TotalOut),
rateIn: parseFloat(stats.RateIn),
rateOut: parseFloat(stats.RateOut)
})
})
yield * res.ndjson()
}
return bw
})