Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
duplexer3
Advanced tools
Package description
The duplexer3 npm package is used to create a duplex stream that combines a writable and readable stream into a single stream. This is useful when you need to expose a single stream interface while internally piping data between two separate streams, such as a process's stdin and stdout.
Combining writable and readable streams
This code sample demonstrates how to create a duplex stream by combining a writable and a readable stream using duplexer3. The resulting duplexStream can be used to read from and write to, acting as a bridge between the two streams.
const { Duplex } = require('stream');
const duplexer3 = require('duplexer3');
const writable = new Duplex({
write(chunk, encoding, callback) {
// Write logic here
callback();
}
});
const readable = new Duplex({
read(size) {
// Read logic here
}
});
const duplexStream = duplexer3(writable, readable);
// Now duplexStream can be used as both a writable and readable stream.
Duplexify is similar to duplexer3 in that it also combines a writable and readable stream into a single duplex stream. However, duplexify allows for the streams to be set asynchronously and provides more options for error handling and stream destruction.
Pumpify combines an array of streams into a single duplex stream, similar to duplexer3's functionality of combining two streams. It uses pump for stream error handling, which automatically cleans up the streams if one of them closes or errors.
Stream-combiner2 is another package that combines multiple streams into one. It differs from duplexer3 by allowing more than two streams to be combined and by being a part of a larger stream transformation framework.
Readme
Like duplexer2 but using Streams3 without readable-stream dependency
var stream = require("stream");
var duplexer3 = require("duplexer3");
var writable = new stream.Writable({objectMode: true}),
readable = new stream.Readable({objectMode: true});
writable._write = function _write(input, encoding, done) {
if (readable.push(input)) {
return done();
} else {
readable.once("drain", done);
}
};
readable._read = function _read(n) {
// no-op
};
// simulate the readable thing closing after a bit
writable.once("finish", function() {
setTimeout(function() {
readable.push(null);
}, 500);
});
var duplex = duplexer3(writable, readable);
duplex.on("data", function(e) {
console.log("got data", JSON.stringify(e));
});
duplex.on("finish", function() {
console.log("got finish event");
});
duplex.on("end", function() {
console.log("got end event");
});
duplex.write("oh, hi there", function() {
console.log("finished writing");
});
duplex.end(function() {
console.log("finished ending");
});
got data "oh, hi there"
finished writing
got finish event
finished ending
got end event
This is a reimplementation of duplexer using the Streams3 API which is standard in Node as of v4. Everything largely works the same.
$ npm i duplexer3
Creates a new DuplexWrapper
object, which is the actual class that implements
most of the fun stuff. All that fun stuff is hidden. DON'T LOOK.
duplexer3([options], writable, readable)
const duplex = duplexer3(new stream.Writable(), new stream.Readable());
Arguments
stream.Duplex
options, as
well as the properties described below.Options
true
.3-clause BSD. A copy is included with the source.
FAQs
Modern version of `duplexer2`
The npm package duplexer3 receives a total of 5,851,313 weekly downloads. As such, duplexer3 popularity was classified as popular.
We found that duplexer3 demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.