through2 0.6.1 → 0.6.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +20 -30
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -1,34 +1,16 @@
1
1
  # through2
2
2
 
3
- <!--
4
-
5
- soon ...
6
-
7
- [![Build Status](https://secure.travis-ci.org/rvagg/through2.png)](http://travis-ci.org/rvagg/through2)
8
-
9
- [![Build Status](https://saucelabs.com/browser-matrix/through2-sauce.svg)](https://travis-ci.org/rvagg/through2)
10
-
11
- -->
12
-
13
- [![NPM](https://nodei.co/npm/through2.png?compact=true)](https://nodei.co/npm/through2/)
14
-
15
- <!--
16
- not happy with these, we need to peg to readable-stream@1.0.x so it'll always report out-of-date
17
-
18
- [![david-dm](https://david-dm.org/rvagg/through2.png)](https://david-dm.org/rvagg/through2/)
19
- [![david-dm](https://david-dm.org/rvagg/through2/dev-status.png)](https://david-dm.org/rvagg/through2#info=devDependencies/)
20
- -->
3
+ [![NPM](https://nodei.co/npm/through2.png?downloads&downloadRank)](https://nodei.co/npm/through2/)
21
4
 
22
5
  **A tiny wrapper around Node streams.Transform (Streams2) to avoid explicit subclassing noise**
23
6
 
24
7
  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) { ... })`.
25
8
 
26
- Note: A **Streams3** version of through2 is available in npm with the tag `"1.0"` rather than `"latest"` so an `npm install through2` will get you the current Streams2 version (version number is 0.x.x). To use a Streams3 version use `npm install through2@1` to fetch the latest version 1.x.x. More information about Streams2 vs Streams3 and recommendations [here](http://www.nearform.com/nodecrunch/dont-use-nodes-core-stream-module).
9
+ Note: A **Streams3** version of through2 is available in npm with the tag `"1.0"` rather than `"latest"` so an `npm install through2` will get you the current Streams2 version (version number is 0.x.x). To use a Streams3 version use `npm install through2@1` to fetch the latest version 1.x.x. More information about Streams2 vs Streams3 and recommendations see the article **[Why I don't use Node's core 'stream' module](http://r.va.gg/2014/06/why-i-dont-use-nodes-core-stream-module.html)**.
27
10
 
28
11
  ```js
29
12
  fs.createReadStream('ex.txt')
30
13
  .pipe(through2(function (chunk, enc, callback) {
31
-
32
14
  for (var i = 0; i < chunk.length; i++)
33
15
  if (chunk[i] == 97)
34
16
  chunk[i] = 122 // swap 'a' for 'z'
@@ -36,7 +18,6 @@ fs.createReadStream('ex.txt')
36
18
  this.push(chunk)
37
19
 
38
20
  callback()
39
-
40
21
  }))
41
22
  .pipe(fs.createWriteStream('out.txt'))
42
23
  ```
@@ -49,17 +30,14 @@ var all = []
49
30
  fs.createReadStream('data.csv')
50
31
  .pipe(csv2())
51
32
  .pipe(through2.obj(function (chunk, enc, callback) {
52
-
53
33
  var data = {
54
34
  name : chunk[0]
55
35
  , address : chunk[3]
56
36
  , phone : chunk[10]
57
37
  }
58
-
59
38
  this.push(data)
60
39
 
61
40
  callback()
62
-
63
41
  }))
64
42
  .on('data', function (data) {
65
43
  all.push(data)
@@ -85,12 +63,12 @@ The `options` argument is first, unlike standard convention, because if I'm pass
85
63
 
86
64
  ```js
87
65
  fs.createReadStream('/tmp/important.dat')
88
- .pipe(through2({ objectMode: true, allowHalfOpen: false }, function (chunk, enc, cb) {
89
-
90
- this.push(new Buffer('wut?'))
91
- cb()
92
-
93
- })
66
+ .pipe(through2({ objectMode: true, allowHalfOpen: false },
67
+ function (chunk, enc, cb) {
68
+ cb(null, 'wut?') // note we can use the second argument on the callback
69
+ // to provide data as an alternative to this.push('wut?')
70
+ }
71
+ )
94
72
  .pipe(fs.createWriteStream('/tmp/wut.txt'))
95
73
  ```
96
74
 
@@ -108,6 +86,18 @@ If you **do not provide a `transformFunction`** then you will get a simple pass-
108
86
 
109
87
  The optional `flushFunction` is provided as the last argument (2nd or 3rd, depending on whether you've supplied options) is called just prior to the stream ending. Can be used to finish up any processing that may be in progress.
110
88
 
89
+ ```js
90
+ fs.createReadStream('/tmp/important.dat')
91
+ .pipe(through2(
92
+ function (chunk, enc, cb) { cb(null, chunk) }, // transform is a noop
93
+ function (cb) { // flush function
94
+ this.push('tacking on an extra buffer to the end');
95
+ cb();
96
+ }
97
+ ))
98
+ .pipe(fs.createWriteStream('/tmp/wut.txt'));
99
+ ```
100
+
111
101
  <b><code>through2.ctor([ options, ] transformFunction[, flushFunction ])</code></b>
112
102
 
113
103
  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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "through2",
3
- "version": "0.6.1",
3
+ "version": "0.6.5",
4
4
  "description": "A tiny wrapper around Node streams2 Transform to avoid explicit subclassing noise",
5
5
  "main": "through2.js",
6
6
  "scripts": {
@@ -20,7 +20,7 @@
20
20
  "author": "Rod Vagg <r@va.gg> (https://github.com/rvagg)",
21
21
  "license": "MIT",
22
22
  "dependencies": {
23
- "readable-stream": ">=1.0.27-1 <1.1.0-0",
23
+ "readable-stream": ">=1.0.33-1 <1.1.0-0",
24
24
  "xtend": ">=4.0.0 <4.1.0-0"
25
25
  },
26
26
  "devDependencies": {