
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
binary-message-parser
Advanced tools
Puts together size-prefixed binary messages from received bytes. Works with pipes.
Puts together size-prefixed binary messages from received bytes. Works with pipes.
const fs = require('fs');
const Parser = require('binary-message-parser');
const rawData = Buffer.from([0, 0, 0, 8, 0, 0, 0, 5, 0, 0, 0, 8, 0, 1, 0, 0]);
// parser requires header extractor object which determines sizes of messages
// from their header bytes
const parser = new Parser(Parser.HeaderExtractorInt32BE);
// message is a Buffer containing all of the message bytes including header
parser.on('message', message => {
console.log('message size:', message.readInt32BE(0),
'data:', message.readInt32BE(4));
});
parser.on('error', (err, args) => {
console.log('error:', err, args);
});
// give data to the parser manually
parser.parseBytes(rawData);
// create file and pipe its contents to the parser
const filePath = './test.dat';
fs.writeFileSync(filePath, rawData);
fs.createReadStream(filePath)
.pipe(parser)
.on('finish', () => { fs.unlinkSync(filePath); });
Expected output:
message size: 8 data: 5
message size: 8 data: 65536
message size: 8 data: 5
message size: 8 data: 65536
Header extractor is an object responsible for determining size of the message based on given header bytes.
Header extractors for some POD data types are available:
const Parser = require('binary-message-parser');
Parser.HeaderExtractorInt8
Parser.HeaderExtractorUInt8
Parser.HeaderExtractorInt16LE
Parser.HeaderExtractorUInt16LE
Parser.HeaderExtractorInt16BE
Parser.HeaderExtractorUInt16BE
Parser.HeaderExtractorInt32LE
Parser.HeaderExtractorUInt32LE
Parser.HeaderExtractorInt32BE
Parser.HeaderExtractorUInt32BE
Example of custom header extractor:
var customHeaderExtractor = {
// number indicating number of bytes header consists of
headerByteCount : 6,
/*
* this method returns number of bytes message consists of (including
* header bytes)
* @param {Buffer} buffer contains header bytes
*/
extractMessageSize : buffer => {
return buffer.readInt16BE(0) + buffer.readInt32BE(2);
},
/*
* this method is optional, by default always returns true
* returns true if message size is in valid range, false otherwise
* when false is returned 'error' event is emitted and parser object is
* shutdown (no longer usable).
* @param {Number} message size
*/
validateMessageSize : size => {
return size >= headerByteCount;
},
}
mocha
FAQs
Puts together size-prefixed binary messages from received bytes. Works with pipes.
We found that binary-message-parser demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.