Socket
Socket
Sign inDemoInstall

toflush

Package Overview
Dependencies
0
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    toflush

Process an entire object mode stream in a single function call.


Version published
Weekly downloads
1
Maintainers
1
Created
Weekly downloads
 

Readme

Source

toflush

Transform on Flush. Process an entire object mode stream in a single function call.

Install

npm install --save toflush

Usage

May have a synchronous callback.

fs.createReadStream('./rows.db') // newline delimited json
  .pipe(split(JSON.parse))
  .pipe(toflush(JSON.stringify))
  .pipe(fs.createWriteStream('./database.json')) // write out as a JSON array

May have a asynchronous, Promise returning, callback.

fs.createReadStream('./images.db')
  .pipe(split(JSON.parse))
  .pipe(toflush(items => {
    return fetch(items[0].url).then(response => {
      if (response.ok) {
        return response.buffer();
      }

      throw new Error(`${response.status} ${response.statusText}`);
    });
  })
  .on('error', error => /* handle fetch or response error */)
  .pipe(fs.createWriteStream('./first.png'));

There are more examples available in the documentation and in the test cases.

API

A single function that receives either an options object or a callback.

toflush(options) -> stream.Transform

  • options.callback - function that receives all objects from the stream as the first argument. Should return an object, array, or a promise. More detail below.
  • options.name - String name to use in error message. Default toflush. May also be provide by the callback name.
  • options.stream - Boolean sanity flag that makes vinyl content streams opt-in.

toflush(callback) -> stream.Transform

Same as the callback in the options above. Any thrown error or rejection is emitted by the stream.

  • callback(items) -> Object - take all objects, and return a single object.
  • callback(items) -> Object[] - take all objects, and return any number of objects. May be the same, more, or less than the input. Each item is pushed into the stream, not the array.
  • callback(items) -> Promise<Object> - take all objects, and then promise a single object.
  • callback(items) -> Promise<Object[]> - take all objects, and then promise any number of objects. May be the same, more, or less than the input. Each item is pushed into the stream, not the array.

Required

You must be using node.js v4.x or later. This module has no dependencies, taking advantage of the improved stream.Transform implementation.

  • vinyl - virtual file format, used heavily by gulp.
  • get-stream - get stream as a string, buffer, or array.
  • through2 - older general stream utility. Heavily inspired this project.

License

MIT © Cody A. Taylor 2018

Keywords

FAQs

Last updated on 13 Jan 2018

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc