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

emit-stream

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

emit-stream - npm Package Compare versions

Comparing version 0.0.0 to 0.1.0

5

example/client-server/client.js
var emitStream = require('../../');
var JSONStream = require('JSONStream');
var net = require('net');
var stream = net.connect(5555);
var stream = net.connect(5555)
.pipe(JSONStream.parse([true]))
;
var ev = emitStream(stream);

@@ -6,0 +9,0 @@

6

example/client-server/server.js
var emitStream = require('../../');
var JSONStream = require('JSONStream');
var EventEmitter = require('events').EventEmitter;

@@ -9,3 +10,6 @@ var net = require('net');

return net.createServer(function (stream) {
emitStream(ev).pipe(stream);
emitStream(ev)
.pipe(JSONStream.stringify())
.pipe(stream)
;
});

@@ -12,0 +16,0 @@ })();

var emitStream = require('../');
var EventEmitter = require('events').EventEmitter;
var JSONStream = require('JSONStream');
var net = require('net');

@@ -7,6 +8,8 @@

var ev = createEmitter();
var s = emitStream(ev);
return net.createServer(function (stream) {
s.pipe(stream);
emitStream(ev)
.pipe(JSONStream.stringify())
.pipe(stream)
;
});

@@ -17,3 +20,5 @@ })();

server.on('listening', function () {
var stream = net.connect(5555);
var stream = net.connect(5555)
.pipe(JSONStream.parse([true]))
;
var ev = emitStream(stream);

@@ -20,0 +25,0 @@

var EventEmitter = require('events').EventEmitter;
var JSONStream = require('JSONStream');
var through = require('through');

@@ -12,3 +12,11 @@ exports = module.exports = function (ev) {

exports.toStream = function (ev) {
var s = JSONStream.stringify();
var s = through(
function write (args) {
this.emit('data', args);
},
function end () {
var ix = ev._emitStreams.indexOf(s);
ev._emitStreams.splice(ix, 1);
}
);

@@ -31,9 +39,2 @@ if (!ev._emitStreams) {

var end = s.end;
s.end = function () {
var ix = ev._emitStreams.indexOf(s);
ev._emitStreams.splice(ix, 1);
end.apply(s, arguments);
};
return s;

@@ -45,9 +46,7 @@ };

var p = JSONStream.parse([ true ]);
p.on('data', function (args) {
s.pipe(through(function (args) {
ev.emit.apply(ev, args);
});
s.pipe(p);
}));
return ev;
};
{
"name" : "emit-stream",
"version" : "0.0.0",
"version" : "0.1.0",
"description" : "turn event emitters into streams and streams into event emitters",
"main" : "index.js",
"bin" : {},
"directories" : {

@@ -12,6 +11,7 @@ "example" : "example",

"dependencies" : {
"JSONStream" : "~0.3.1"
"through" : "~0.1.4"
},
"devDependencies" : {
"tap" : "~0.3.0"
"tap" : "~0.3.0",
"JSONStream" : "~0.3.1"
},

@@ -18,0 +18,0 @@ "scripts" : {

@@ -6,2 +6,3 @@ var test = require('tap').test;

var net = require('net');
var JSONStream = require('JSONStream');

@@ -16,3 +17,5 @@ test('emit', function (t) {

if (!ev) ev = createEmitter();
emitStream(ev).pipe(stream);
var s = JSONStream.stringify();
s.pipe(stream);
emitStream(ev).pipe(s);
});

@@ -28,3 +31,3 @@ server.on('close', function () { ev.stop() });

var stream = net.connect(5555);
var ev = emitStream(stream);
var ev = emitStream(stream.pipe(JSONStream.parse([true])));

@@ -31,0 +34,0 @@ ev.on('ping', function (t) {

Sorry, the diff of this file is not supported yet

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