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

Commit

Permalink
feat: adds ipfs.block.rm method (#1123)
Browse files Browse the repository at this point in the history
* feat: adds ipfs.block.rm method
* chore: fix up interface tests
  • Loading branch information
achingbrain authored Oct 6, 2019
1 parent 038c4d9 commit 2f0eff7
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 3 deletions.
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)
}
}
})

0 comments on commit 2f0eff7

Please sign in to comment.