kubo-rpc-client
Version:
A client library for the Kubo RPC API
31 lines • 930 B
JavaScript
import { CID } from 'multiformats/cid';
import { toUrlSearchParams } from '../lib/to-url-search-params.js';
export function createRm(client) {
return async function* rm(cid, options = {}) {
if (!Array.isArray(cid)) {
cid = [cid];
}
const res = await client.post('block/rm', {
signal: options.signal,
searchParams: toUrlSearchParams({
arg: cid.map(cid => cid.toString()),
'stream-channels': true,
...options
}),
headers: options.headers
});
for await (const removed of res.ndjson()) {
yield toCoreInterface(removed);
}
};
}
function toCoreInterface(removed) {
const out = {
cid: CID.parse(removed.Hash)
};
if (removed.Error != null) {
out.error = new Error(removed.Error);
}
return out;
}
//# sourceMappingURL=rm.js.map