
Security News
Another Round of TEA Protocol Spam Floods npm, But It’s Not a Worm
Recent coverage mislabels the latest TEA protocol spam as a worm. Here’s what’s actually happening.
length-prefixed-json-stream
Advanced tools
A length-prefixed JSON stream reader that accommodates whitespace padding
A length-prefixed JSON stream reader that accommodates whitespace padding.
Length prefixed JSON streams are streams of JSON values, where each value is preceded by the length-in-bytes of the value. (The length is a decimal integer encoded as a string of digits.) Here's an example:
18{"message": "Hi!"}27{"message": "How are you?"}
This module supports ASCII whitespace characters both before and after the length prefix. This has the effect of allowing literal number values to be sent without necessitating a wrapper object, by simply appending a space after the length prefix string. For example:
2 42 2 84 3 168 4 0.42
import JSONStreamIterator from 'length-prefixed-json-stream'
async function responseHandler (response) {
const streamIterator = new JSONStreamIterator(response)
let value
while ((value = await streamIterator.readNextValue()) !== undefined) {
console.log(value)
}
}
If your JavaScript environment supports it, you can use the more readable for await…of:
async function responseHandler (response) {
const streamIterator = new JSONStreamIterator(response)
for await (const value of streamIterator) {
console.log(value)
}
}
import JSONStreamIterator from 'length-prefixed-json-stream'
Reads values one at a time from stream.
stream: Node.js readable stream.Returns a promise that resolves to the next value from the input stream. When the stream ends, the promise will resolve to undefined. If there is an error parsing the stream, or some sort of connection error, the promise will be rejected with the error.
A for await…of (async iterator) compatible method. If you are using for await…of, this is called for you, but you can also use it explicitly if you would like. It wraps the returned values according to the spec: while not complete, returns a promise that resolves to {done: false, value: …}, and when complete, returns a promise that resolves to {done: false}.
Also a part of the async iterator spec, but you can call it explicitly to end iteration early and free resources.
FAQs
A length-prefixed JSON stream reader that accommodates whitespace padding
The npm package length-prefixed-json-stream receives a total of 67 weekly downloads. As such, length-prefixed-json-stream popularity was classified as not popular.
We found that length-prefixed-json-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
Recent coverage mislabels the latest TEA protocol spam as a worm. Here’s what’s actually happening.

Security News
PyPI adds Trusted Publishing support for GitLab Self-Managed as adoption reaches 25% of uploads

Research
/Security News
A malicious Chrome extension posing as an Ethereum wallet steals seed phrases by encoding them into Sui transactions, enabling full wallet takeover.