Home
Docs
GitHub
Pricing
Blog
Log In

Run Sandworm Audit for your App

Get started
Generated on Feb 26, 2024 via pnpm

through2 2.0.5

A tiny wrapper around Node streams2 Transform to avoid explicit subclassing noise
Package summary
Share
0
issues
2
licenses
9
MIT
1
ISC
Package created
1 Aug 2013
Version published
6 Nov 2018
Maintainers
2
Total deps
10
Direct deps
2
License
MIT

Issues

0
This package has no issues

Licenses

MIT License

Permissive
OSI Approved
This is a human-readable summary of (and not a substitute for) the license. Disclaimer.
Can
commercial-use
modify
distribute
sublicense
private-use
Cannot
hold-liable
Must
include-copyright
include-license
9 Packages, Including:
core-util-is@1.0.3
isarray@1.0.0
process-nextick-args@2.0.1
readable-stream@2.3.8
safe-buffer@5.1.2
string_decoder@1.1.1
through2@2.0.5
util-deprecate@1.0.2
xtend@4.0.2

ISC License

Permissive
OSI Approved
This is a human-readable summary of (and not a substitute for) the license. Disclaimer.
Can
commercial-use
modify
distribute
Cannot
hold-liable
Must
include-copyright
include-license
1 Packages, Including:
inherits@2.0.4
Disclaimer

This deed highlights only some of the key features and terms of the actual license. It is not a license and has no legal value. You should carefully review all of the terms and conditions of the actual license before using the licensed material.

Sandworm is not a law firm and does not provide legal services. Distributing, displaying, or linking to this deed or the license that it summarizes does not create a lawyer-client or any other relationship.

Direct Dependencies

2
All Dependencies CSV
ⓘ This is a list of through2 's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.
NameVersionSizeLicenseTypeVulnerabilities
readable-stream2.3.825.14 kBMIT
prod
xtend4.0.22.47 kBMIT
prod

Visualizations

Frequently Asked Questions

What does through2 do?

Through2 is a tiny, efficient Node.js library that wraps around the streams.Transform interface. This allows for an easy-to-use way to handle stream transforms without the complications and verbosity of subclassing. Inspired by Dominic Tarr's 'through' package, through2 offers an easier way to create a stream out of a function. Its main use is in systems and processes dealing with stream manipulation or transformation, such as reading files, transforming data, and feeding the transformed results into a writeable stream.

How do you use through2?

The use of through2 is straightforward and revolves around passing in a transform function. Here’s a code example of through2 being used to read from a file, manipulate the data, and then write to another file:

const through2 = require('through2');
const fs = require('fs');

fs.createReadStream('ex.txt')
  .pipe(through2(function (chunk, enc, callback) {
    for (let i = 0; i < chunk.length; i++)
      if (chunk[i] == 97)
        chunk[i] = 122 // swap 'a' for 'z'
    this.push(chunk)
    callback()
  }))
  .pipe(fs.createWriteStream('out.txt'))
  .on('finish', () => console.log('Done!'));

The second code example shows an object stream:

const all = [];
fs.createReadStream('data.csv')
  .pipe(csv2())
  .pipe(through2.obj(function (chunk, enc, callback) {
    const data = {
        name    : chunk[0],
        address : chunk[3],
        phone   : chunk[10]
    }
    this.push(data)
    callback()
  }))
  .on('data', (data) => {
    all.push(data)
  })
  .on('end', () => {
    console.log(all)
  })

These examples show through2 working with both plain data and object streams.

Where are the through2 docs?

The documentation for through2 is contained within its Readme file on Github, specifically at https://github.com/rvagg/through2. A detailed explanation of the API, including its methods and options, is provided. For a complete understanding of through2’s transform and flush functions, refer to the stream.Transform documentation on the Node.js official site at https://nodejs.org/api/stream.html#stream_class_stream_transform.