Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
multicodec
Advanced tools
The multicodec npm package is a self-describing multiformat, which is useful for identifying the format of a given piece of data. It is used extensively in the IPFS ecosystem to handle various data formats in a consistent manner.
Encoding and Decoding
This feature allows you to encode a buffer with a specific codec and decode it to find out the codec used. The `addPrefix` method adds a prefix to the buffer, and the `rmPrefix` method removes it.
const multicodec = require('multicodec');
// Encoding a buffer with a specific codec
const buffer = Buffer.from('hello world');
const encoded = multicodec.addPrefix('raw', buffer);
console.log(encoded);
// Decoding a buffer to find out the codec
const decoded = multicodec.rmPrefix(encoded);
console.log(decoded);
Listing Supported Codecs
This feature allows you to list all the supported codecs in the multicodec package. The `print` property contains a list of all the codecs.
const multicodec = require('multicodec');
// Listing all supported codecs
const codecs = multicodec.print;
console.log(codecs);
Resolving Codec Names and Codes
This feature allows you to resolve codec names to their corresponding codes and vice versa. The `getCodeVarint` method returns the code for a given codec name, and the `getName` method returns the name for a given codec code.
const multicodec = require('multicodec');
// Resolving codec name to code
const code = multicodec.getCodeVarint('dag-pb');
console.log(code);
// Resolving codec code to name
const name = multicodec.getName(0x70);
console.log(name);
The multihashes package is used for creating and working with self-describing hashes. It is similar to multicodec in that it provides a way to handle multiple formats in a consistent manner, but it is specifically focused on hash functions.
The multibase package is used for encoding and decoding data in various base encodings. It is similar to multicodec in that it provides a way to handle multiple formats, but it is specifically focused on base encodings.
The multiformats package is a collection of self-describing formats including multibase, multihash, and multicodec. It provides a unified interface for working with these formats, making it a more comprehensive solution compared to using multicodec alone.
JavaScript implementation of the multicodec specification
> npm install multicodec
const multicodec = require('multicodec')
const prefixedProtobuf = multicodec.addPrefix('protobuf', protobufBuffer)
// prefixedProtobuf 0x50...
// The multicodec codec values can be accessed directly:
console.log(multicodec.DAG_CBOR)
// 113
// To get the string representation of a codec, e.g. for error messages:
console.log(multicodec.getNameFromCode(113))
// dag-cbor
https://multiformats.github.io/js-multicodec/
Updating the lookup table is done with a script. The source of truth is the multicodec default table. Update the table with running:
npm run update-table
Contributions welcome. Please check out the issues.
Check out our contributing document for more information on how we work, and about contributing in general. Please be aware that all interactions related to multiformats are subject to the IPFS Code of Conduct.
Small note: If editing the README, please conform to the standard-readme specification.
MIT © 2016 Protocol Labs Inc.
FAQs
JavaScript implementation of the multicodec specification
The npm package multicodec receives a total of 525,136 weekly downloads. As such, multicodec popularity was classified as popular.
We found that multicodec demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 6 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.