Skip to content

Commit 8904d3d

Browse files
committed
fix: performance improvement conversion
1 parent 4b05367 commit 8904d3d

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/convert.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ function buf2str (buf) {
126126

127127
function mh2buf (hash) {
128128
// the address is a varint prefixed multihash string representation
129-
const mh = bs58.decode((new CID(hash)).toString('base58btc'))
129+
const mh = new CID(hash).multihash
130130
const size = Buffer.from(varint.encode(mh.length))
131131
return Buffer.concat([size, mh])
132132
}

test/index.spec.js

+7
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,13 @@ describe('variants', () => {
356356
expect(addr.toString()).to.equal(str)
357357
})
358358

359+
it('p2p', () => {
360+
const str = '/p2p/bafzbeidt255unskpefjmqb2rc27vjuyxopkxgaylxij6pw35hhys4vnyp4'
361+
const addr = multiaddr(str)
362+
expect(addr).to.have.property('buffer')
363+
expect(addr.toString()).to.equal('/p2p/QmW8rAgaaA6sRydK1k6vonShQME47aDxaFidbtMevWs73t')
364+
})
365+
359366
it('ipfs', () => {
360367
const str = '/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC'
361368
const addr = multiaddr(str)

0 commit comments

Comments
 (0)