Skip to content

Instantly share code, notes, and snippets.

@myndzi
Last active August 29, 2015 14:22
Show Gist options
  • Save myndzi/95a729021ba5012798c4 to your computer and use it in GitHub Desktop.
Save myndzi/95a729021ba5012798c4 to your computer and use it in GitHub Desktop.
'use strict';
var Transform = require('stream').Transform,
inherits = require('util').inherits,
fs = require('fs');
function ConcatStream() {
Transform.call(this, {
writableObjectMode: true
});
}
inherits(ConcatStream, Transform);
ConcatStream.prototype._transform = function (obj, ignore, callback) {
var stream = fs.createReadStream(obj.path),
self = this;
stream.on('data', function (chunk) {
self.push(chunk);
});
stream.on('error', function (err) {
callback(err);
});
stream.on('end', function () {
callback();
});
};
var test = new ConcatStream();
test.write({ path: __filename })
test.write({ path: __filename })
test.on('data', function (chunk) {
console.log(chunk.toString());
});
test.end();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment