🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

stream-recorder

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stream-recorder

A Duplex stream which collects all chunks passed through

latest
Source
npmnpm
Version
0.3.3
Version published
Maintainers
1
Created
Source

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.

Keywords

passthrough

FAQs

Package last updated on 18 Jan 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts