This repository has been archived by the owner on Mar 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 300
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adds ipfs.block.rm method (#1123)
* feat: adds ipfs.block.rm method * chore: fix up interface tests
- Loading branch information
1 parent
038c4d9
commit 2f0eff7
Showing
3 changed files
with
51 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
}) |