0.3.3 • Published 10 years ago

stream-recorder v0.3.3

Weekly downloads
3
License
MIT
Repository
github
Last release
10 years ago

stream-recorder Dependencies Status Image Build Status Image Coverage Status

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'), // npm install stream-from-array
    input = ['foo', 'bar'];

streamFromArray(input)
  .pipe(Recorder(function(buffer){
    // it's not an object stream, so buffer is a node buffer
    console.log(buffer.toString()); // output: foobar
  }))
  .resume(); // switch into flowing-mode (!)

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) {
        // it's an object stream, so buffer is an array - of gulp files
        console.log(buffer[0].contents); // dunno what yourAwsomeGulpPlugin does :-)
        done();
      }))
      .resume(); // switch into flowing-mode (!)

  });
});

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.

0.3.3

10 years ago

0.3.2

10 years ago

0.3.1

11 years ago

0.3.0

11 years ago

0.2.1

11 years ago

0.2.0

11 years ago

0.1.1

11 years ago

0.1.0

11 years ago