Socket
Book a DemoInstallSign in
Socket

collect-transform-stream

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

collect-transform-stream

create a transform stream that runs a function over all collected elements

0.0.1
Source
npmnpm
Version published
Weekly downloads
145
530.43%
Maintainers
1
Weekly downloads
 
Created
Source

collect-transform-stream

create a transform stream that runs a function over all collected elements

Sometimes you end up in a situation where you have a stream pipeline like

pump(source, transform, destination)

but you have another transform function that needs to process all elements in the stream before passing them on, e.g. filtering duplicates from an unordered stream:

pump(source, collectAndFilter, transform, destination)

collect-transform-stream is a tiny module that provides this.

Usage

var collect = require('collect-transform-stream')
var uniq = require('uniq')
var from = require('from2')

var source = from.obj(new Array(100).fill(0).map(function () {
  return Math.floor(Math.random() * 10)
}))

var dedupe = collect(function (nums) {
  return uniq(nums)
})

source.pipe(dedupe)

dedupe.on('data', function (n) {
  console.log(n)
})

outputs

0
1
2
3
4
5
6
7
8
9

API

var collect = require('collect-transform-stream')

collect(fn[, cb])

Create a Transform stream that runs the function fn on all incoming objects at once, then pipes elements individually onward to the next stream in the pipeline.

Use return result to use synchronously; call cb(err, result) to use asynchronously.

Install

With npm installed, run

$ npm install collect-transform-stream

License

ISC

FAQs

Package last updated on 24 Mar 2017

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

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.