through2 0.1.0 → 0.2.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 +6 -1
- package/package.json +6 -6
- package/test.js +2 -2
- package/through2.js +7 -0
package/README.md
CHANGED
|
@@ -4,6 +4,9 @@
|
|
|
4
4
|
|
|
5
5
|
[](https://nodei.co/npm/through2/)
|
|
6
6
|
|
|
7
|
+
[](https://david-dm.org/rvagg/through2/)
|
|
8
|
+
[](https://david-dm.org/rvagg/through2#info=devDependencies/)
|
|
9
|
+
|
|
7
10
|
**A tiny wrapper around Node streams.Transform (Streams2) to avoid explicit subclassing noise**
|
|
8
11
|
|
|
9
12
|
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) { ... })`.
|
|
@@ -45,7 +48,7 @@ fs.createReadStream('data.csv')
|
|
|
45
48
|
|
|
46
49
|
## API
|
|
47
50
|
|
|
48
|
-
<b><code>through2([ options, ] transformFunction[, flushFunction ])</code></b>
|
|
51
|
+
<b><code>through2([ options, ] [ transformFunction ] [, flushFunction ])</code></b>
|
|
49
52
|
|
|
50
53
|
Consult the **[stream.Transform](http://nodejs.org/docs/latest/api/stream.html#stream_class_stream_transform)** documentation for the exact rules of the `transformFunction` (i.e. `this._transform`) and the optional `flushFunction` (i.e. `this._flush`).
|
|
51
54
|
|
|
@@ -70,6 +73,8 @@ The `transformFunction` must have the following signature: `function (chunk, enc
|
|
|
70
73
|
|
|
71
74
|
To queue a new chunk, call `this.push(chunk)`—this can be called as many times as required before the `callback()` if you have multiple pieces to send on.
|
|
72
75
|
|
|
76
|
+
If you **do not provide a `transformFunction`** then you will get a simple simple pass-through stream.
|
|
77
|
+
|
|
73
78
|
### flushFunction
|
|
74
79
|
|
|
75
80
|
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.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "through2",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "A tiny wrapper around Node streams2 Transform to avoid explicit subclassing noise",
|
|
5
5
|
"main": "through2.js",
|
|
6
6
|
"scripts": {
|
|
@@ -19,12 +19,12 @@
|
|
|
19
19
|
"author": "Rod Vagg <r@va.gg> (https://github.com/rvagg)",
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"readable-stream": "~1.
|
|
23
|
-
"xtend": "~2.
|
|
22
|
+
"readable-stream": "~1.1.9",
|
|
23
|
+
"xtend": "~2.1.1"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"tape": "~1.
|
|
27
|
-
"bl": "~0.
|
|
28
|
-
"stream-spigot": "~2.
|
|
26
|
+
"tape": "~1.1.1",
|
|
27
|
+
"bl": "~0.4.1",
|
|
28
|
+
"stream-spigot": "~2.1.2"
|
|
29
29
|
}
|
|
30
30
|
}
|
package/test.js
CHANGED
|
@@ -214,12 +214,12 @@ test('pipeable object through ctor', function (t) {
|
|
|
214
214
|
t.deepEqual(o, { temp: expect.shift(), unit: 'C' }, 'got transformed object')
|
|
215
215
|
})
|
|
216
216
|
|
|
217
|
-
spigot([
|
|
217
|
+
spigot({objectMode: true}, [
|
|
218
218
|
{temp: -2.2, unit: 'F'},
|
|
219
219
|
{temp: -40, unit: 'F'},
|
|
220
220
|
{temp: 212, unit: 'F'},
|
|
221
221
|
{temp: 22, unit: 'C'}
|
|
222
|
-
]
|
|
222
|
+
]).pipe(th2)
|
|
223
223
|
})
|
|
224
224
|
|
|
225
225
|
test('object through ctor override', function (t) {
|
package/through2.js
CHANGED
|
@@ -2,6 +2,10 @@ const Transform = require('stream').Transform || require('readable-stream/transf
|
|
|
2
2
|
, inherits = require('util').inherits
|
|
3
3
|
, xtend = require('xtend')
|
|
4
4
|
|
|
5
|
+
function noop (chunk, enc, callback) {
|
|
6
|
+
callback(null, chunk)
|
|
7
|
+
}
|
|
8
|
+
|
|
5
9
|
function ctor (options, transform, flush) {
|
|
6
10
|
if (typeof options == 'function') {
|
|
7
11
|
flush = transform
|
|
@@ -9,6 +13,9 @@ function ctor (options, transform, flush) {
|
|
|
9
13
|
options = {}
|
|
10
14
|
}
|
|
11
15
|
|
|
16
|
+
if (typeof transform != 'function')
|
|
17
|
+
transform = noop
|
|
18
|
+
|
|
12
19
|
function Through2 (override) {
|
|
13
20
|
if (!(this instanceof Through2))
|
|
14
21
|
return new Through2(override)
|