stream-recorder

A Duplex stream which collects all chunks passed through.

Usage no npm install needed!

<script type="module">
  import streamRecorder from 'https://cdn.skypack.dev/stream-recorder';
</script>

README

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.