ipfs-http-client
Version:
A client library for the IPFS HTTP API
38 lines (33 loc) • 973 B
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
var cid = require('multiformats/cid');
var configure = require('../lib/configure.js');
var toUrlSearchParams = require('../lib/to-url-search-params.js');
const createRm = configure.configure(api => {
async function* rm(cid, options = {}) {
if (!Array.isArray(cid)) {
cid = [cid];
}
const res = await api.post('block/rm', {
signal: options.signal,
searchParams: toUrlSearchParams.toUrlSearchParams({
arg: cid.map(cid => cid.toString()),
'stream-channels': true,
...options
}),
headers: options.headers
});
for await (const removed of res.ndjson()) {
yield toCoreInterface(removed);
}
}
return rm;
});
function toCoreInterface(removed) {
const out = { cid: cid.CID.parse(removed.Hash) };
if (removed.Error) {
out.error = new Error(removed.Error);
}
return out;
}
exports.createRm = createRm;