Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
fluent-stream
Advanced tools
Parsing octet-data from stream/buffer can be painful, this is what fluent-stream aiming for.
var fluent = require('fluent-stream').create()
fluent
// pop 2 bytes
.pop(2, function (buf) {
console.log(buf) // log: <Buffer 01 02>
})
// async pop
.pop(1, function (buf, done) {
setTimeout(function () {
console.log(buf) // log: <Buffer 03>
done()
}, 100)
})
// unpredictable length
.pop(1, function (buf) {
console.log(buf) // log: <Buffer 04>
return 2 // next pop length
})
.pop(function (buf, done) { // 2 bytes
console.log(buf) // log: <Buffer 05 06>
done(2) // next pop length
})
.pop(function (buf) {
console.log(buf) // log: <Buffer 07 08>
})
// remaining data will be emited(Stream)
.on('data', function (buf) {
console.log(buf) // log: <Buffer 09>
})
// write or pipe data to it
f.write(new Buffer([0x1, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09]))
$ npm install fluent-stream
var FluentStream = require('fluent-stream')
Return a fluent-stream object, it is a duplex stream
Pop n length buffer and exec callback when fluent received enough bytes(>= nbytes)
Discard those data if callback not exists
If callback has more than 1 params, it will be treat as a async callback, you must call done(2nd param) to finish this pop.
If callback return a Number(sync: return n, async: done(n)), it indicate that next pop action will pop n bytes. This is very useful in handling unpredictable length buffer.
There is a 'stash' prop in fluent, it is a Object, all stashed buffers will be stored in it.
Pop buffer and stash it in 'stash' keyed 'stashName'.
Apply stash, you can accese stashed buffers in it, such as console.log(stash.stashName)
There are a dozen of methods can pre-parse buffer to corresponding types, such as int, float, double
fluent.readInt8(function (value) {
console.log(value) //log: 1
})
fluent.write(new Buffer([0x01]))
They are…
Details see here Node Buffer Doc
FluentStream is duplex stream implemented, you can pipe readable stream to it and pipe it to other writable stream.
Fluent will pop buffer of specified length then emit remaining buffer.
eg.
var http = require('http')
, FluentStream = require('fluent-stream')
http.createServer(function (rep, res) {
rep.pipe(FluentStream.create()
.pop(1, function (buf) {
// do something...
})
).pipe(res)
}).listen(8000)
MIT
FAQs
Fluent octet-stream handling
We found that fluent-stream 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
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.