
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.
tcp-stream is a NodeJS I/O Stream Utility, inspired by Rust's Tokio Crate, intended to control complex stream reads on TCP.
This library abstracts from NodeJS's read event implemented on stream.Readable, by providing Promise-based methods like read, readExact, readUntil and readEOF.
const TcpStream = require("tcp-stream");
const tls = require("tls");
const netSocket = tls.connect({
host: "google.com",
servername: "google.com",
port: 443,
ALPNProtocols: ['http/1.1', 'http/1.0']
});
const stream = new TcpStream(netSocket, 1024);
async function run() {
await stream.write(`GET / HTTP/1.1\r\nHost: google.com\r\n\r\n`);
const line = (await stream.readUntil("\n")).toString();
console.log(line);
}
run();
The Stream Class is the default export of this library, it's a class that takes in the Socket and Max Read Size.
Socket (optional by passing `null`): when specified the Stream class will take responisbility of adding event listener on `read` and `close` event
Max Read Size (default value of 1 MiB, must be a Integer Number): the limit of the internal Buffer Size before it pauses reads, this will impact the amount of bytes you can read from `read` and `readExact` and may cause `readUntil` and `readEOF` to throw a Error if it runs out.
When the stream closes before the read methods can complete it will throw a Stream Closed error.
When the stream throttles because Read Buffer has reached its limit, and therefore is unable to fulfill a read method it will throw a Stream Read Limit error, and close the stream.
read and readExact methodsThe read(N) and readExact(N) methods both read up to N bytes from the stream, however only readExact(N) garantuees that it will return exactly N bytes.
readUntil methodThe readUntil(delim: String or Buffer) method will return a inclusive buffer up to the next delimiter, the function garantuees it will not return until the delimiter is present.
readEOF methodThe readEOF() will return when the Stream Closes with everything in the Read Buffers.
FAQs
TCP Stream Utility Package for Node.js inspired by Rust's Tokio
We found that tcp-stream demonstrated a healthy version release cadence and project activity because the last version was released less than 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.