
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.
multiplex-stream
Advanced tools
Multiplex multiple streams through a single stream
npm install stream-multiplex
var MultiplexStream = require('multiplex-stream');
// create downstream multiplex that listens for connections
var downstreamMultiplex = new MultiplexStream(function(downstreamConnection) {
// a multiplexed stream has connected from upstream.
// The assigned id will be accessible as downstreamConnection.id
downstreamConnection.setEncoding();
downstreamConnection.on('data', function(data) {
// received data, send reply upstream
downstreamConnection.write('Hello, upstream');
});
downstreamConnection.on('end', function(data) {
// downstream connection has ended
});
});
// create upstream multiplex that will be used to initiate connections
var upstreamMultiplex = new MultiplexStream({
// The connectTimeout optionally specifies how long to
// wait in milliseconds for the downstream multiplex to
// accept to connections. It defaults to 3000 milliseconds
connectTimeout: 5000
});
// pipe from one multiplex to the other (there could
// be other carrier streams in between, for instance a net socket)
upstreamMultiplex.pipe(downstreamMultiplex).pipe(upstreamMultiplex);
// create a new upstream multiplexed stream
var upstreamConnection = upstreamMultiplex.connect({
// optionally specify an id for the stream. By default
// a v1 UUID will be assigned as the id for anonymous streams
id: 'MyStream'
}, function() {
upstreamConnection.setEncoding();
upstreamConnection.on('data', function(data) {
// received reply, end the connection
upstreamConnection.end();
});
upstreamConnection.on('end', function(data) {
// upstream connection has ended
});
// send some data downstream
upstreamConnection.write('Hello, downstream');
}).on('error', function(error) {
// timeouts and other errors resulting from connect requests
});
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using ./grunt.sh or .\grunt.bat.
Copyright (c) 2012 Peter Halliday
Licensed under the MIT license.
FAQs
Multiplex multiple streams through a single stream
The npm package multiplex-stream receives a total of 4 weekly downloads. As such, multiplex-stream popularity was classified as not popular.
We found that multiplex-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
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.