
Product
Announcing Socket Certified Patches: One-Click Fixes for Vulnerable Dependencies
A safer, faster way to eliminate vulnerabilities without updating dependencies
@vweevers/length-prefixed-stream
Advanced tools
Streaming equivalent of length-prefixed-message. This module allow you to send Buffers with a varint length prefix to ensure that they will arrive unpartioned. A fork of mafintosh/length-prefixed-stream (2.0.0) that upgraded readable-stream from 3 to 4.
With npm do:
npm i @vweevers/length-prefixed-stream
const lpstream = require('@vweevers/length-prefixed-stream')
const encode = lpstream.encode() // create an encode stream to send data
const decode = lpstream.decode() // create an decode stream to receive data
encode.write('hello world') // send "hello world"
decode.on('data', function(data) {
console.log(data.toString()) // will always print "hello world"
})
encode.pipe(decode) // for testing just pipe to our selves
This library encodes each chunks as follows:
<length-of-chunk-1> <chunk-1> <length-of-chunk-2> <chunk-2> …
The length of the following chunk is encoded using varint, which follows the protobuf-style varint encoding.
As an example, we're going to encode two ASCII chunks:
1st chunk:
68 65 79 hey
2nd chunk:
68 65 6c 6c 6f 20 77 6f 72 6c 64 hello world
Encoded using length-prefixed-stream, they look like this:
03 varint-encoded length of 1st chunk
68 65 79 1st chunk (3 bytes)
0b varint-encoded length ()of 2nd chunk
68 65 6c 6c 6f 20 77 6f 72 6c 64 2nd chunk (11 bytes)
transformStream = lpstream.encode()Creates a new encoder transform stream.
transformStream = lpstream.decode()Creates a new decoder transform stream.
MIT
FAQs
Streaming length prefixed buffers
We found that @vweevers/length-prefixed-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.

Product
A safer, faster way to eliminate vulnerabilities without updating dependencies

Product
Reachability analysis for Ruby is now in beta, helping teams identify which vulnerabilities are truly exploitable in their applications.

Research
/Security News
Malicious npm packages use Adspect cloaking and fake CAPTCHAs to fingerprint visitors and redirect victims to crypto-themed scam sites.