Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

feat: adds ipfs.block.rm method #1123

Merged
merged 2 commits into from
Oct 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
"browser-process-platform": "~0.1.1",
"cross-env": "^6.0.0",
"go-ipfs-dep": "^0.4.22",
"interface-ipfs-core": "^0.117.0",
"interface-ipfs-core": "^0.117.2",
"ipfsd-ctl": "^0.47.1",
"nock": "^11.3.2",
"stream-equal": "^1.1.1"
Expand Down
15 changes: 13 additions & 2 deletions src/block/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
'use strict'

const nodeify = require('promise-nodeify')
const moduleConfig = require('../utils/module-config')
const { collectify } = require('../lib/converters')

module.exports = (arg) => {
module.exports = (arg, config) => {
const send = moduleConfig(arg)
const rm = require('./rm-async-iterator')(config)

return {
get: require('./get')(send),
stat: require('./stat')(send),
put: require('./put')(send)
put: require('./put')(send),
rm: (input, options, callback) => {
if (typeof options === 'function') {
callback = options
options = {}
}
return nodeify(collectify(rm)(input, options), callback)
},
_rmAsyncIterator: rm
}
}
37 changes: 37 additions & 0 deletions src/block/rm-async-iterator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
'use strict'

const CID = require('cids')
const ndjson = require('iterable-ndjson')
const configure = require('../lib/configure')
const toIterable = require('../lib/stream-to-iterable')
const toCamel = require('../lib/object-to-camel')

module.exports = configure(({ ky }) => {
return async function * removeBlock (cid, options) {
options = options || {}

if (!Array.isArray(cid)) {
cid = [cid]
}

const searchParams = new URLSearchParams()
searchParams.set('stream-channels', true)
searchParams.set('force', options.force || false)
searchParams.set('quiet', options.quiet || false)

cid.forEach(cid => {
searchParams.append('arg', new CID(cid).toString())
})

const res = await ky.post('block/rm', {
timeout: options.timeout,
signal: options.signal,
headers: options.headers,
searchParams
})

for await (const removed of ndjson(toIterable(res.body))) {
yield toCamel(removed)
}
}
})