Skip to content
This repository was archived by the owner on Sep 29, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function getCodec (prefixedData) {
}

/**
* Get the name of the codec.
* Get the name of the codec (human friendly).
*
* @param {CodecNumber} codec
* @returns {CodecName|undefined}
Expand Down Expand Up @@ -129,9 +129,6 @@ function getVarint (code) {
// Make the constants top-level constants
const constants = require('./constants')

// Human friendly names for printing, e.g. in error messages
const print = require('./print')

module.exports = {
addPrefix,
rmPrefix,
Expand All @@ -141,6 +138,5 @@ module.exports = {
getCode,
getCodeVarint,
getVarint,
print,
...constants
}
4 changes: 3 additions & 1 deletion src/int-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ const nameTable = new Map()

for (const encodingName in baseTable) {
const code = baseTable[encodingName]
nameTable.set(code, /** @type {CodecName} */(encodingName))
if (!nameTable.has(code)) {
nameTable.set(code, /** @type {CodecName} */(encodingName))
}
}

module.exports = Object.freeze(nameTable)
16 changes: 0 additions & 16 deletions src/print.js

This file was deleted.

20 changes: 10 additions & 10 deletions test/multicodec.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,20 @@ describe('multicodec', () => {
})

it('returns the name from codec number', () => {
expect(multicodec.print[144]).to.eql('eth-block')
expect(multicodec.print[112]).to.eql('dag-pb')
expect(multicodec.print[0x0111]).to.eql('udp')
expect(multicodec.print[0xb201]).to.eql('blake2b-8')

expect(multicodec.print[multicodec.ETH_BLOCK]).to.eql('eth-block')
expect(multicodec.print[multicodec.DAG_PB]).to.eql('dag-pb')
expect(multicodec.print[multicodec.UDP]).to.eql('udp')
expect(multicodec.print[multicodec.BLAKE2B_8]).to.eql('blake2b-8')
expect(multicodec.getName(144)).to.eql('eth-block')
expect(multicodec.getName(112)).to.eql('dag-pb')
expect(multicodec.getName(0x0111)).to.eql('udp')
expect(multicodec.getName(0xb201)).to.eql('blake2b-8')

expect(multicodec.getName(multicodec.ETH_BLOCK)).to.eql('eth-block')
expect(multicodec.getName(multicodec.DAG_PB)).to.eql('dag-pb')
expect(multicodec.getName(multicodec.UDP)).to.eql('udp')
expect(multicodec.getName(multicodec.BLAKE2B_8)).to.eql('blake2b-8')
})

it('returns p2p when 0x01a5 is used', () => {
// `ipfs` and `p2p` are assigned to `0x01a5`, `ipfs` is deprecated
expect(multicodec.print[0x01a5]).to.eql('p2p')
expect(multicodec.getName(0x01a5)).to.eql('p2p')
})

it('throws error on unknown codec name when getting the code', () => {
Expand Down