Skip to content

Commit ead9f08

Browse files
committed
readme tweaks
1 parent 164d3f8 commit ead9f08

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

README.md

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
# through2
22

3+
![Build & Test](https://github.com/rvagg/through2/workflows/Build%20&%20Test/badge.svg)
4+
35
[![NPM](https://nodei.co/npm/through2.png?downloads&downloadRank)](https://nodei.co/npm/through2/)
46

57
**A tiny wrapper around Node.js streams.Transform (Streams2/3) to avoid explicit subclassing noise**
68

79
Inspired by [Dominic Tarr](https://github.com/dominictarr)'s [through](https://github.com/dominictarr/through) in that it's so much easier to make a stream out of a function than it is to set up the prototype chain properly: `through(function (chunk) { ... })`.
810

9-
***Note: Users of Node.js 0.10 and 0.12 should install `through2@2.x`. As of through2@3.x, readable-stream@3 is being used and is not compatible with older versions of Node.js.*** _v2.x support is being maintained on the [v2.x](https://github.com/rvagg/through2/tree/v2.x) branch._
10-
1111
```js
1212
fs.createReadStream('ex.txt')
1313
.pipe(through2(function (chunk, enc, callback) {
14-
for (var i = 0; i < chunk.length; i++)
14+
for (let i = 0; i < chunk.length; i++)
1515
if (chunk[i] == 97)
1616
chunk[i] = 122 // swap 'a' for 'z'
1717

@@ -26,12 +26,12 @@ fs.createReadStream('ex.txt')
2626
Or object streams:
2727

2828
```js
29-
var all = []
29+
const all = []
3030

3131
fs.createReadStream('data.csv')
3232
.pipe(csv2())
3333
.pipe(through2.obj(function (chunk, enc, callback) {
34-
var data = {
34+
conat data = {
3535
name : chunk[0]
3636
, address : chunk[3]
3737
, phone : chunk[10]
@@ -50,6 +50,20 @@ fs.createReadStream('data.csv')
5050

5151
Note that `through2.obj(fn)` is a convenience wrapper around `through2({ objectMode: true }, fn)`.
5252

53+
## Do you need this?
54+
55+
Since Node.js introduced [Simplified Stream Construction](https://nodejs.org/api/stream.html#stream_simplified_construction), many uses of **through2** have become redundant. Consider whether you really need to use **through2** or just want to use the core `'stream'` package (or ideally the `'readable-stream'` package from npm):
56+
57+
```js
58+
const { Transform } = require('stream')
59+
60+
const transformer = new Transform({
61+
transform(chunk, enc, callback) {
62+
// ...
63+
}
64+
})
65+
```
66+
5367
## API
5468

5569
<b><code>through2([ options, ] [ transformFunction ] [, flushFunction ])</code></b>
@@ -104,7 +118,7 @@ fs.createReadStream('/tmp/important.dat')
104118
Instead of returning a `stream.Transform` instance, `through2.ctor()` returns a **constructor** for a custom Transform. This is useful when you want to use the same transform logic in multiple instances.
105119

106120
```js
107-
var FToC = through2.ctor({objectMode: true}, function (record, encoding, callback) {
121+
const FToC = through2.ctor({objectMode: true}, function (record, encoding, callback) {
108122
if (record.temp != null && record.unit == "F") {
109123
record.temp = ( ( record.temp - 32 ) * 5 ) / 9
110124
record.unit = "C"
@@ -114,21 +128,13 @@ var FToC = through2.ctor({objectMode: true}, function (record, encoding, callbac
114128
})
115129

116130
// Create instances of FToC like so:
117-
var converter = new FToC()
131+
constconverter = new FToC()
118132
// Or:
119-
var converter = FToC()
133+
const converter = FToC()
120134
// Or specify/override options when you instantiate, if you prefer:
121-
var converter = FToC({objectMode: true})
135+
const converter = FToC({objectMode: true})
122136
```
123137

124-
## See Also
125-
126-
- [through2-map](https://github.com/brycebaril/through2-map) - Array.prototype.map analog for streams.
127-
- [through2-filter](https://github.com/brycebaril/through2-filter) - Array.prototype.filter analog for streams.
128-
- [through2-reduce](https://github.com/brycebaril/through2-reduce) - Array.prototype.reduce analog for streams.
129-
- [through2-spy](https://github.com/brycebaril/through2-spy) - Wrapper for simple stream.PassThrough spies.
130-
- the [mississippi stream utility collection](https://github.com/maxogden/mississippi) includes `through2` as well as many more useful stream modules similar to this one
131-
132138
## License
133139

134-
**through2** is Copyright (c) Rod Vagg and additional contributors and licensed under the MIT license. All rights not explicitly granted in the MIT license are reserved. See the included LICENSE file for more details.
140+
**through2** is Copyright &copy; Rod Vagg and additional contributors and licensed under the MIT license. All rights not explicitly granted in the MIT license are reserved. See the included LICENSE file for more details.

0 commit comments

Comments
 (0)