Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit 2f0eff7

Browse files
authored
feat: adds ipfs.block.rm method (#1123)
* feat: adds ipfs.block.rm method * chore: fix up interface tests
1 parent 038c4d9 commit 2f0eff7

File tree

3 files changed

+51
-3
lines changed

3 files changed

+51
-3
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
"browser-process-platform": "~0.1.1",
108108
"cross-env": "^6.0.0",
109109
"go-ipfs-dep": "^0.4.22",
110-
"interface-ipfs-core": "^0.117.0",
110+
"interface-ipfs-core": "^0.117.2",
111111
"ipfsd-ctl": "^0.47.1",
112112
"nock": "^11.3.2",
113113
"stream-equal": "^1.1.1"

src/block/index.js

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
11
'use strict'
22

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

5-
module.exports = (arg) => {
7+
module.exports = (arg, config) => {
68
const send = moduleConfig(arg)
9+
const rm = require('./rm-async-iterator')(config)
710

811
return {
912
get: require('./get')(send),
1013
stat: require('./stat')(send),
11-
put: require('./put')(send)
14+
put: require('./put')(send),
15+
rm: (input, options, callback) => {
16+
if (typeof options === 'function') {
17+
callback = options
18+
options = {}
19+
}
20+
return nodeify(collectify(rm)(input, options), callback)
21+
},
22+
_rmAsyncIterator: rm
1223
}
1324
}

src/block/rm-async-iterator.js

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
'use strict'
2+
3+
const CID = require('cids')
4+
const ndjson = require('iterable-ndjson')
5+
const configure = require('../lib/configure')
6+
const toIterable = require('../lib/stream-to-iterable')
7+
const toCamel = require('../lib/object-to-camel')
8+
9+
module.exports = configure(({ ky }) => {
10+
return async function * removeBlock (cid, options) {
11+
options = options || {}
12+
13+
if (!Array.isArray(cid)) {
14+
cid = [cid]
15+
}
16+
17+
const searchParams = new URLSearchParams()
18+
searchParams.set('stream-channels', true)
19+
searchParams.set('force', options.force || false)
20+
searchParams.set('quiet', options.quiet || false)
21+
22+
cid.forEach(cid => {
23+
searchParams.append('arg', new CID(cid).toString())
24+
})
25+
26+
const res = await ky.post('block/rm', {
27+
timeout: options.timeout,
28+
signal: options.signal,
29+
headers: options.headers,
30+
searchParams
31+
})
32+
33+
for await (const removed of ndjson(toIterable(res.body))) {
34+
yield toCamel(removed)
35+
}
36+
}
37+
})

0 commit comments

Comments
 (0)