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

Commit dc7d3fd

Browse files
committed
fix(bitswap.unwant) parse CID from arg just like block.add does
1 parent b644c16 commit dc7d3fd

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/bitswap/unwant.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,33 @@
11
'use strict'
22

33
const promisify = require('promisify-es6')
4+
const CID = require('cids')
45

56
module.exports = (send) => {
67
return promisify((args, opts, callback) => {
78
if (typeof (opts) === 'function') {
89
callback = opts
910
opts = {}
1011
}
12+
13+
// Mirrors block.get's parsing of the CID
14+
let cid
15+
try {
16+
if (CID.isCID(args)) {
17+
cid = args
18+
args = cid.toBaseEncodedString()
19+
} else if (Buffer.isBuffer(args)) {
20+
cid = new CID(args)
21+
args = cid.toBaseEncodedString()
22+
} else if (typeof args === 'string') {
23+
cid = new CID(args)
24+
} else {
25+
return callback(new Error('invalid argument'))
26+
}
27+
} catch (err) {
28+
return callback(err)
29+
}
30+
1131
send({
1232
path: 'bitswap/unwant',
1333
args: args,

0 commit comments

Comments
 (0)