ipfs-http-client
Version:
A client library for the IPFS HTTP API
30 lines • 840 B
JavaScript
import { CID } from 'multiformats/cid';
import { configure } from '../lib/configure.js';
import { toUrlSearchParams } from '../lib/to-url-search-params.js';
export const createRm = 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({
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.parse(removed.Hash) };
if (removed.Error) {
out.error = new Error(removed.Error);
}
return out;
}