emit-stream
Advanced tools
Comparing version 0.0.0 to 0.1.0
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 @@ |
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 @@ |
25
index.js
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9060
175
118
2
+ Addedthrough@~0.1.4
+ Addedthrough@0.1.4(transitive)
- RemovedJSONStream@~0.3.1
- RemovedJSONStream@0.3.3(transitive)
- Removedjsonparse@0.0.1(transitive)