Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
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 multicodec = require('multicodec')
const prefixedProtobuf = multicodec.addPrefix('protobuf', protobufBuffer)
// prefixedProtobuf 0x50...
https://multiformats.github.io/js-multicodec/
Captain: @diasdavid.
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
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
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.