stream-recorder

A Duplex stream which collects all chunks passed through.
npm install stream-recorder --save
Usage
Streams of strings
Then pipe through a recorder instance and retrieve the buffer:
var Recorder = require('stream-recorder'),
streamFromArray = require('stream-from-array'),
input = ['foo', 'bar'];
streamFromArray(input)
.pipe(Recorder(function(buffer){
console.log(buffer.toString());
}))
.resume();
Test your Gulpplugins with stream-recorder
Gulp files are vinyl files:
npm install vinyl
var streamFromValue = require('stream-from-value');
var File = require('vinyl');
var helloFile = new File({
cwd: '/',
base: '/hello/',
path: '/hello/world.js',
contents: new Buffer('console.log("Hello world!");')
});
describe('yourAwsomeGulpPlugin', function() {
it('should process gulp (vinyl) files', function(done) {
streamFromValue.obj(helloFile)
.pipe(yourAwsomeGulpPlugin())
.pipe(Recorder.obj(function(buffer) {
console.log(buffer[0].contents);
done();
}))
.resume();
});
});
API
Class: StreamRecorder
StreamRecorder are Transform streams.
new StreamRecorder([options], [finishCallback])
- options
Object passed through new stream.Transform([options])
- finishCallback
Function (buffer) This Callback is called during the finish event of StreamRecorder
Note: The new operator can be omitted.
StreamRecorder.buffer
- In
objectMode it is the array of JavaScript values (number | object | string | ... ) passed through
- Otherwise it is a node Buffer which contains the values of
strings and buffers passed through
StreamRecorder#obj([options], [finishCallback])
A convenience wrapper for new StreamRecorder({objectMode: true, ...}, finishCallback).
License
Copyright (c) 2014 Michael Mayer
Licensed under the MIT license.