through2 0.6.2 → 0.6.3
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.
- package/README.md +18 -11
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -28,7 +28,6 @@ Note: A **Streams3** version of through2 is available in npm with the tag `"1.0"
|
|
|
28
28
|
```js
|
|
29
29
|
fs.createReadStream('ex.txt')
|
|
30
30
|
.pipe(through2(function (chunk, enc, callback) {
|
|
31
|
-
|
|
32
31
|
for (var i = 0; i < chunk.length; i++)
|
|
33
32
|
if (chunk[i] == 97)
|
|
34
33
|
chunk[i] = 122 // swap 'a' for 'z'
|
|
@@ -36,7 +35,6 @@ fs.createReadStream('ex.txt')
|
|
|
36
35
|
this.push(chunk)
|
|
37
36
|
|
|
38
37
|
callback()
|
|
39
|
-
|
|
40
38
|
}))
|
|
41
39
|
.pipe(fs.createWriteStream('out.txt'))
|
|
42
40
|
```
|
|
@@ -49,17 +47,14 @@ var all = []
|
|
|
49
47
|
fs.createReadStream('data.csv')
|
|
50
48
|
.pipe(csv2())
|
|
51
49
|
.pipe(through2.obj(function (chunk, enc, callback) {
|
|
52
|
-
|
|
53
50
|
var data = {
|
|
54
51
|
name : chunk[0]
|
|
55
52
|
, address : chunk[3]
|
|
56
53
|
, phone : chunk[10]
|
|
57
54
|
}
|
|
58
|
-
|
|
59
55
|
this.push(data)
|
|
60
56
|
|
|
61
57
|
callback()
|
|
62
|
-
|
|
63
58
|
}))
|
|
64
59
|
.on('data', function (data) {
|
|
65
60
|
all.push(data)
|
|
@@ -85,12 +80,12 @@ The `options` argument is first, unlike standard convention, because if I'm pass
|
|
|
85
80
|
|
|
86
81
|
```js
|
|
87
82
|
fs.createReadStream('/tmp/important.dat')
|
|
88
|
-
.pipe(through2({ objectMode: true, allowHalfOpen: false },
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
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
|
+
)
|
|
94
89
|
.pipe(fs.createWriteStream('/tmp/wut.txt'))
|
|
95
90
|
```
|
|
96
91
|
|
|
@@ -108,6 +103,18 @@ If you **do not provide a `transformFunction`** then you will get a simple pass-
|
|
|
108
103
|
|
|
109
104
|
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
105
|
|
|
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
|
+
|
|
111
118
|
<b><code>through2.ctor([ options, ] transformFunction[, flushFunction ])</code></b>
|
|
112
119
|
|
|
113
120
|
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.
|
|
3
|
+
"version": "0.6.3",
|
|
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.
|
|
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": {
|