Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

stream-demux

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stream-demux - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

4

package.json
{
"name": "stream-demux",
"version": "1.0.0",
"version": "1.0.1",
"description": "An iterable asynchronous stream demultiplexer.",

@@ -28,5 +28,5 @@ "main": "index.js",

"devDependencies": {
"iterable-async-stream": "^1.0.3",
"iterable-async-stream": "^1.0.7",
"mocha": "^5.0.5"
}
}

@@ -0,1 +1,2 @@

const assert = require('assert');
const StreamDemux = require('../index');

@@ -12,3 +13,3 @@ const IterableAsyncStream = require('iterable-async-stream');

describe('StreamDemux tests', () => {
describe('StreamDemux', () => {
let stream;

@@ -22,3 +23,3 @@ let demux;

it('Should work', async () => {
it('should multiplex across a single stream and demultiplex across multiple substreams', async () => {
(async () => {

@@ -31,9 +32,33 @@ for (let i = 0; i < 10; i++) {

demux.end('hello');
demux.end('abc');
})();
let substream = demux.getStream('hello');
for await (let data of substream) {
console.log('DATA:', data);
}
let receivedHelloPackets = [];
let receivedAbcPackets = [];
await Promise.all([
(async () => {
let substream = demux.getStream('hello');
for await (let packet of substream) {
receivedHelloPackets.push(packet);
}
})(),
(async () => {
let substream = demux.getStream('abc');
for await (let packet of substream) {
receivedAbcPackets.push(packet);
}
})()
]);
assert.equal(receivedHelloPackets.length, 10);
assert.equal(receivedHelloPackets[0], 'world0');
assert.equal(receivedHelloPackets[1], 'world1');
assert.equal(receivedHelloPackets[9], 'world9');
assert.equal(receivedAbcPackets.length, 10);
assert.equal(receivedAbcPackets[0], 'def0');
assert.equal(receivedAbcPackets[1], 'def1');
assert.equal(receivedAbcPackets[9], 'def9');
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc