Comparing version 0.1.0 to 0.1.1
{ | ||
"name": "st-stream", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Combine transform streams into one stream", | ||
@@ -18,4 +18,3 @@ "main": "stStream.js", | ||
"mocha": "^2.2.5", | ||
"sinon": "^1.15.4", | ||
"through2": "^2.0.0" | ||
"sinon": "^1.15.4" | ||
}, | ||
@@ -22,0 +21,0 @@ "repository": { |
# st-stream | ||
Install with `npm install st-stream` | ||
###example | ||
```javascript | ||
var stStream = require('st-stream'); | ||
var transform1 = stStream.transform(function(obj, e, done) { | ||
obj.msg = obj.msg + ' - first transform'; | ||
this.push(obj); | ||
done(); | ||
}); | ||
var transform2 = stStream.transform(function(obj, e, done) { | ||
obj.msg = obj.msg + ' - second transform'; | ||
this.push(obj); | ||
done(); | ||
}); | ||
var myStream = stStream.combine([transform1, transform2]); | ||
myStream.write({msg: 'hello'}); | ||
myStream.write({msg: 'hello2'}); | ||
myStream.write({msg: 'hello3'}); | ||
myStream.end(); | ||
myStream.on('data', function(objData) { | ||
console.log(objData); | ||
}).on('finish', function() { | ||
console.log('All done'); | ||
}); | ||
``` | ||
Output | ||
{ msg: 'hello - first transform' } | ||
{ msg: 'hello2 - second transform' } | ||
{ msg: 'hello3 - first transform' } | ||
All done |
'use strict'; | ||
var stream = require('stream'); | ||
//var through2 = require('through2'); | ||
var sinon = require('sinon'); | ||
var net = require('net'); | ||
var stStream = require('./stStream.js'); | ||
//var ConcurrentStream = require('./concurrentStream.js'); | ||
describe('Stream Duplex test', function() { | ||
it('should send and transform data', function(doneTest) { | ||
describe('st stream main tests', function() { | ||
it('should send and transform data from local stream', function(doneTest) { | ||
var dataSpy = sinon.spy(); | ||
var transform1 = stStream.transform(function(obj, e, done) { | ||
@@ -31,4 +31,8 @@ obj.msg = obj.msg + ' - first transform'; | ||
myStream.on('data', function(objData) { | ||
console.log(objData); | ||
dataSpy(objData); | ||
}).on('finish', function() { | ||
sinon.assert.calledWith(dataSpy, {msg: 'hello - first transform'}); | ||
sinon.assert.calledWith(dataSpy, {msg: 'hello2 - second transform'}); | ||
sinon.assert.calledWith(dataSpy, {msg: 'hello3 - first transform'}); | ||
sinon.assert.calledThrice(dataSpy); | ||
doneTest(); | ||
@@ -38,8 +42,4 @@ }); | ||
it('should test', function(doneTest) { | ||
var transform1 = stStream.transform(function(data, enc, done) { | ||
data.msg = data.msg + ':stream1'; | ||
this.push(data); | ||
done(); | ||
}); | ||
it.skip('should send and receive on multiple network streams', function(doneTest) { | ||
var dataSpy = sinon.spy(); | ||
@@ -54,6 +54,2 @@ var server1 = net.createServer(function(data) { | ||
data.pipe(transformStream).pipe(data); | ||
//setTimeout(function() { | ||
// data.end(); | ||
//}, 100); | ||
}); | ||
@@ -64,4 +60,17 @@ server1.listen(3001); | ||
var cd = stStream.combine([client1, transform1]); | ||
var server2 = net.createServer(function(data) { | ||
var transformStream = stStream.transform(function(obj, e, done) { | ||
obj.msg = obj.msg + ':server2'; | ||
this.push(obj); | ||
done(); | ||
}); | ||
data.pipe(transformStream).pipe(data); | ||
}); | ||
server2.listen(3002); | ||
var client2 = net.connect(3002); | ||
var cd = stStream.combine([client1, client2]); | ||
cd.write({'msg': 'hello'}); | ||
@@ -72,18 +81,59 @@ cd.write({'msg': 'hello2'}); | ||
var receivedDataServers = {}; | ||
cd.on('data', function(d) { | ||
console.log('data received'); | ||
console.log(d); | ||
var splitted = d.msg.split(':'); | ||
dataSpy(d); | ||
}).on('finish', function() { | ||
console.log('finished'); | ||
sinon.assert.calledWith(dataSpy, {msg: 'hello:server1'}); | ||
sinon.assert.calledWith(dataSpy, {msg: 'hello2:server1'}); | ||
sinon.assert.calledWith(dataSpy, {msg: 'hello3:server1'}); | ||
sinon.assert.calledThrice(dataSpy); | ||
doneTest(); | ||
}); | ||
}); | ||
//dest.on('finish', function() { | ||
// console.log('FINISH EVENT FIRED'); | ||
it('should send and receive over network stream', function(doneTest) { | ||
var dataSpy = sinon.spy(); | ||
//var transform1 = stStream.transform(function(data, enc, done) { | ||
// data.msg = data.msg + ':stream1'; | ||
// this.push(data); | ||
// done(); | ||
//}); | ||
//dest.on('end', function() { | ||
// console.log('END EVENT FIRED'); | ||
//}); | ||
var server1 = net.createServer(function(data) { | ||
var transformStream = stStream.transform(function(obj, e, done) { | ||
obj.msg = obj.msg + ':server1'; | ||
this.push(obj); | ||
done(); | ||
}); | ||
data.pipe(transformStream).pipe(data); | ||
}); | ||
server1.listen(3001); | ||
var client1 = net.connect(3001); | ||
var cd = stStream.combine([client1]); | ||
cd.write({'msg': 'hello'}); | ||
cd.write({'msg': 'hello2'}); | ||
cd.write({'msg': 'hello3'}); | ||
cd.end(); | ||
cd.on('data', function(d) { | ||
dataSpy(d); | ||
}).on('finish', function() { | ||
sinon.assert.calledWith(dataSpy, {msg: 'hello:server1'}); | ||
sinon.assert.calledWith(dataSpy, {msg: 'hello2:server1'}); | ||
sinon.assert.calledWith(dataSpy, {msg: 'hello3:server1'}); | ||
sinon.assert.calledThrice(dataSpy); | ||
doneTest(); | ||
}); | ||
}); | ||
it('should end stream on stream.push(null)', function(doneTest) { | ||
}); | ||
}); |
@@ -203,3 +203,13 @@ 'use strict'; | ||
return duplexer(lineStream, dest); | ||
var returnedStream = duplexer(lineStream, dest); | ||
returnedStream.pause = function() { | ||
lineStream.pause(); | ||
}; | ||
returnedStream.resume = function() { | ||
lineStream.resume(); | ||
}; | ||
return returnedStream; | ||
}; |
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
10771
2
269
40