through2 0.6.4 → 1.1.1

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 +13 -20
  2. package/package.json +5 -2
package/README.md CHANGED
@@ -10,7 +10,7 @@ soon ...
10
10
 
11
11
  -->
12
12
 
13
- [![NPM](https://nodei.co/npm/through2.png?downloads&downloadRank)](https://nodei.co/npm/through2/)
13
+ [![NPM](https://nodei.co/npm/through2.png?compact=true)](https://nodei.co/npm/through2/)
14
14
 
15
15
  <!--
16
16
  not happy with these, we need to peg to readable-stream@1.0.x so it'll always report out-of-date
@@ -23,11 +23,12 @@ not happy with these, we need to peg to readable-stream@1.0.x so it'll always re
23
23
 
24
24
  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
25
 
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 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)**.
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).
27
27
 
28
28
  ```js
29
29
  fs.createReadStream('ex.txt')
30
30
  .pipe(through2(function (chunk, enc, callback) {
31
+
31
32
  for (var i = 0; i < chunk.length; i++)
32
33
  if (chunk[i] == 97)
33
34
  chunk[i] = 122 // swap 'a' for 'z'
@@ -35,6 +36,7 @@ fs.createReadStream('ex.txt')
35
36
  this.push(chunk)
36
37
 
37
38
  callback()
39
+
38
40
  }))
39
41
  .pipe(fs.createWriteStream('out.txt'))
40
42
  ```
@@ -47,14 +49,17 @@ var all = []
47
49
  fs.createReadStream('data.csv')
48
50
  .pipe(csv2())
49
51
  .pipe(through2.obj(function (chunk, enc, callback) {
52
+
50
53
  var data = {
51
54
  name : chunk[0]
52
55
  , address : chunk[3]
53
56
  , phone : chunk[10]
54
57
  }
58
+
55
59
  this.push(data)
56
60
 
57
61
  callback()
62
+
58
63
  }))
59
64
  .on('data', function (data) {
60
65
  all.push(data)
@@ -80,12 +85,12 @@ The `options` argument is first, unlike standard convention, because if I'm pass
80
85
 
81
86
  ```js
82
87
  fs.createReadStream('/tmp/important.dat')
83
- .pipe(through2({ objectMode: true, allowHalfOpen: false },
84
- function (chunk, enc, cb) {
85
- cb(null, 'wut?') // note we can use the second argument on the callback
86
- // to provide data as an alternative to this.push('wut?')
87
- }
88
- )
88
+ .pipe(through2({ objectMode: true, allowHalfOpen: false }, function (chunk, enc, cb) {
89
+
90
+ this.push(new Buffer('wut?'))
91
+ cb()
92
+
93
+ })
89
94
  .pipe(fs.createWriteStream('/tmp/wut.txt'))
90
95
  ```
91
96
 
@@ -103,18 +108,6 @@ If you **do not provide a `transformFunction`** then you will get a simple pass-
103
108
 
104
109
  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.
105
110
 
106
- ```js
107
- fs.createReadStream('/tmp/important.dat')
108
- .pipe(through2(
109
- function (chunk, enc, cb) { cb(null, chunk) }, // transform is a noop
110
- function (cb) { // flush function
111
- this.push('tacking on an extra buffer to the end');
112
- cb();
113
- }
114
- ))
115
- .pipe(fs.createWriteStream('/tmp/wut.txt'));
116
- ```
117
-
118
111
  <b><code>through2.ctor([ options, ] transformFunction[, flushFunction ])</code></b>
119
112
 
120
113
  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.4",
3
+ "version": "1.1.1",
4
4
  "description": "A tiny wrapper around Node streams2 Transform to avoid explicit subclassing noise",
5
5
  "main": "through2.js",
6
6
  "scripts": {
@@ -20,12 +20,15 @@
20
20
  "author": "Rod Vagg <r@va.gg> (https://github.com/rvagg)",
21
21
  "license": "MIT",
22
22
  "dependencies": {
23
- "readable-stream": ">=1.0.33-1 <1.1.0-0",
23
+ "readable-stream": ">=1.1.13-1 <1.2.0-0",
24
24
  "xtend": ">=4.0.0 <4.1.0-0"
25
25
  },
26
26
  "devDependencies": {
27
27
  "bl": ">=0.9.0 <0.10.0-0",
28
28
  "stream-spigot": ">=3.0.4 <3.1.0-0",
29
29
  "tape": ">=2.14.0 <2.15.0-0"
30
+ },
31
+ "publishConfig": {
32
+ "tag": "1.0"
30
33
  }
31
34
  }