through2 0.4.0 → 0.5.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.
package/.npmignore CHANGED
@@ -1 +1,3 @@
1
- node_modules
1
+ test
2
+ .jshintrc
3
+ .travis.yml
package/README.md CHANGED
@@ -10,7 +10,7 @@ soon ...
10
10
 
11
11
  -->
12
12
 
13
- [![NPM](https://nodei.co/npm/through2.png?compact=true)](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,6 +23,8 @@ 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 [here](http://www.nearform.com/nodecrunch/dont-use-nodes-core-stream-module).
27
+
26
28
  ```js
27
29
  fs.createReadStream('ex.txt')
28
30
  .pipe(through2(function (chunk, enc, callback) {
@@ -32,7 +34,7 @@ fs.createReadStream('ex.txt')
32
34
  chunk[i] = 122 // swap 'a' for 'z'
33
35
 
34
36
  this.push(chunk)
35
-
37
+
36
38
  callback()
37
39
 
38
40
  }))
@@ -53,9 +55,9 @@ fs.createReadStream('data.csv')
53
55
  , address : chunk[3]
54
56
  , phone : chunk[10]
55
57
  }
56
-
58
+
57
59
  this.push(data)
58
-
60
+
59
61
  callback()
60
62
 
61
63
  }))
@@ -126,6 +128,13 @@ var converter = FToC()
126
128
  var converter = FToC({objectMode: true})
127
129
  ```
128
130
 
131
+ ## See Also
132
+
133
+ - [through2-map](https://github.com/brycebaril/through2-map) - Array.prototype.map analog for streams.
134
+ - [through2-filter](https://github.com/brycebaril/through2-filter) - Array.prototype.filter analog for streams.
135
+ - [through2-reduce](https://github.com/brycebaril/through2-reduce) - Array.prototype.reduce analog for streams.
136
+ - [through2-spy](https://github.com/brycebaril/through2-spy) - Wrapper for simple stream.PassThrough spies.
137
+
129
138
  ## License
130
139
 
131
140
  **through2** is Copyright (c) 2013 Rod Vagg [@rvagg](https://twitter.com/rvagg) and licenced under the MIT licence. All rights not explicitly granted in the MIT license are reserved. See the included LICENSE file for more details.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "through2",
3
- "version": "0.4.0",
3
+ "version": "0.5.1",
4
4
  "description": "A tiny wrapper around Node streams2 Transform to avoid explicit subclassing noise",
5
5
  "main": "through2.js",
6
6
  "scripts": {
@@ -21,7 +21,7 @@
21
21
  "license": "MIT",
22
22
  "dependencies": {
23
23
  "readable-stream": "~1.0.17",
24
- "xtend": "~2.1.1"
24
+ "xtend": "~3.0.0"
25
25
  },
26
26
  "devDependencies": {
27
27
  "tape": "~2.3.0",
package/through2.js CHANGED
@@ -1,6 +1,6 @@
1
- const Transform = require('readable-stream/transform')
2
- , inherits = require('util').inherits
3
- , xtend = require('xtend')
1
+ var Transform = require('readable-stream/transform')
2
+ , inherits = require('util').inherits
3
+ , xtend = require('xtend')
4
4
 
5
5
 
6
6
  // a noop _transform function
@@ -67,7 +67,7 @@ module.exports.ctor = through2(function (options, transform, flush) {
67
67
 
68
68
 
69
69
  module.exports.obj = through2(function (options, transform, flush) {
70
- var t2 = new Transform(xtend({ objectMode: true }, options))
70
+ var t2 = new Transform(xtend({ objectMode: true, highWaterMark: 16 }, options))
71
71
 
72
72
  t2._transform = transform
73
73
 
package/.jshintrc DELETED
@@ -1,59 +0,0 @@
1
- {
2
- "predef": [ ]
3
- , "bitwise": false
4
- , "camelcase": false
5
- , "curly": false
6
- , "eqeqeq": false
7
- , "forin": false
8
- , "immed": false
9
- , "latedef": false
10
- , "noarg": true
11
- , "noempty": true
12
- , "nonew": true
13
- , "plusplus": false
14
- , "quotmark": true
15
- , "regexp": false
16
- , "undef": true
17
- , "unused": true
18
- , "strict": false
19
- , "trailing": true
20
- , "maxlen": 120
21
- , "asi": true
22
- , "boss": true
23
- , "debug": true
24
- , "eqnull": true
25
- , "esnext": true
26
- , "evil": true
27
- , "expr": true
28
- , "funcscope": false
29
- , "globalstrict": false
30
- , "iterator": false
31
- , "lastsemic": true
32
- , "laxbreak": true
33
- , "laxcomma": true
34
- , "loopfunc": true
35
- , "multistr": false
36
- , "onecase": false
37
- , "proto": false
38
- , "regexdash": false
39
- , "scripturl": true
40
- , "smarttabs": false
41
- , "shadow": false
42
- , "sub": true
43
- , "supernew": false
44
- , "validthis": true
45
- , "browser": true
46
- , "couch": false
47
- , "devel": false
48
- , "dojo": false
49
- , "mootools": false
50
- , "node": true
51
- , "nonstandard": true
52
- , "prototypejs": false
53
- , "rhino": false
54
- , "worker": true
55
- , "wsh": false
56
- , "nomen": false
57
- , "onevar": false
58
- , "passfail": false
59
- }
package/.travis.yml DELETED
@@ -1,17 +0,0 @@
1
- language: node_js
2
- node_js:
3
- - '0.8'
4
- - '0.10'
5
- - '0.11'
6
- branches:
7
- only:
8
- - master
9
- notifications:
10
- email:
11
- - rod@vagg.org
12
- script: npm test
13
- env:
14
- global:
15
- - SAUCE_USER=through2-sauce
16
- - secure: A8KyygIlklZOcTwTGhZHpkOu7Cn4tI1QQasg75CTSjudczGzkuh1pG2RDIkWqGcrWv9o5CjI6fFYYx0JvQu8o5PO+ZAtV1Z0AlnM965vE8kAx0XEC7giAV323bibfnHwyQu74vIhbOfdes7E4/cYerV2kAjK0T375D4DYEpDuvw=
17
-
@@ -1,334 +0,0 @@
1
- const test = require('tape')
2
- , through2 = require('../')
3
- , crypto = require('crypto')
4
- , bl = require('bl')
5
- , spigot = require('stream-spigot')
6
-
7
- test('plain through', function (t) {
8
- var th2 = through2(function (chunk, enc, callback) {
9
- if (!this._i)
10
- this._i = 97 // 'a'
11
- else
12
- this._i++
13
- var b = new Buffer(chunk.length)
14
- for (var i = 0; i < chunk.length; i++)
15
- b[i] = this._i
16
- this.push(b)
17
- callback()
18
- })
19
-
20
- th2.pipe(bl(function (err, b) {
21
- var s = b.toString('ascii')
22
- t.equal('aaaaaaaaaabbbbbcccccccccc', s, 'got transformed string')
23
- t.end()
24
- }))
25
-
26
- th2.write(crypto.randomBytes(10))
27
- th2.write(crypto.randomBytes(5))
28
- th2.write(crypto.randomBytes(10))
29
- th2.end()
30
- })
31
-
32
- test('pipeable through', function (t) {
33
- var th2 = through2(function (chunk, enc, callback) {
34
- if (!this._i)
35
- this._i = 97 // 'a'
36
- else
37
- this._i++
38
- var b = new Buffer(chunk.length)
39
- for (var i = 0; i < chunk.length; i++)
40
- b[i] = this._i
41
- this.push(b)
42
- callback()
43
- })
44
-
45
- th2.pipe(bl(function (err, b) {
46
- var s = b.toString('ascii')
47
- // bl() acts like a proper streams2 stream and passes as much as it's
48
- // asked for, so we really only get one write with such a small amount
49
- // of data
50
- t.equal(s, 'aaaaaaaaaaaaaaaaaaaaaaaaa', 'got transformed string')
51
- t.end()
52
- }))
53
-
54
- var bufs = bl()
55
- bufs.append(crypto.randomBytes(10))
56
- bufs.append(crypto.randomBytes(5))
57
- bufs.append(crypto.randomBytes(10))
58
- bufs.pipe(th2)
59
- })
60
-
61
- test('object through', function (t) {
62
- t.plan(3)
63
-
64
- var th2 = through2({ objectMode: true}, function (chunk, enc, callback) {
65
- this.push({ out: chunk.in + 1 })
66
- callback()
67
- })
68
-
69
- var e = 0
70
- th2.on('data', function (o) {
71
- t.deepEqual(o, { out: e === 0 ? 102 : e == 1 ? 203 : -99 }, 'got transformed object')
72
- e++
73
- })
74
-
75
- th2.write({ in: 101 })
76
- th2.write({ in: 202 })
77
- th2.write({ in: -100 })
78
- th2.end()
79
- })
80
-
81
- test('object through with through2.obj', function (t) {
82
- t.plan(3)
83
-
84
- var th2 = through2.obj(function (chunk, enc, callback) {
85
- this.push({ out: chunk.in + 1 })
86
- callback()
87
- })
88
-
89
- var e = 0
90
- th2.on('data', function (o) {
91
- t.deepEqual(o, { out: e === 0 ? 102 : e == 1 ? 203 : -99 }, 'got transformed object')
92
- e++
93
- })
94
-
95
- th2.write({ in: 101 })
96
- th2.write({ in: 202 })
97
- th2.write({ in: -100 })
98
- th2.end()
99
- })
100
-
101
- test('flushing through', function (t) {
102
- var th2 = through2(function (chunk, enc, callback) {
103
- if (!this._i)
104
- this._i = 97 // 'a'
105
- else
106
- this._i++
107
- var b = new Buffer(chunk.length)
108
- for (var i = 0; i < chunk.length; i++)
109
- b[i] = this._i
110
- this.push(b)
111
- callback()
112
- }, function (callback) {
113
- this.push(new Buffer([ 101, 110, 100 ]))
114
- callback()
115
- })
116
-
117
- th2.pipe(bl(function (err, b) {
118
- var s = b.toString('ascii')
119
- t.equal(s, 'aaaaaaaaaabbbbbccccccccccend', 'got transformed string')
120
- t.end()
121
- }))
122
-
123
- th2.write(crypto.randomBytes(10))
124
- th2.write(crypto.randomBytes(5))
125
- th2.write(crypto.randomBytes(10))
126
- th2.end()
127
- })
128
-
129
- test('plain through ctor', function (t) {
130
- var Th2 = through2.ctor(function (chunk, enc, callback) {
131
- if (!this._i)
132
- this._i = 97 // 'a'
133
- else
134
- this._i++
135
- var b = new Buffer(chunk.length)
136
- for (var i = 0; i < chunk.length; i++)
137
- b[i] = this._i
138
- this.push(b)
139
- callback()
140
- })
141
-
142
- var th2 = new Th2()
143
-
144
- th2.pipe(bl(function (err, b) {
145
- var s = b.toString('ascii')
146
- t.equal('aaaaaaaaaabbbbbcccccccccc', s, 'got transformed string')
147
- t.end()
148
- }))
149
-
150
- th2.write(crypto.randomBytes(10))
151
- th2.write(crypto.randomBytes(5))
152
- th2.write(crypto.randomBytes(10))
153
- th2.end()
154
- })
155
-
156
- test('reuse through ctor', function (t) {
157
- t.plan(4)
158
-
159
- var Th2 = through2.ctor(function (chunk, enc, callback) {
160
- if (!this._i) {
161
- t.ok(1, 'did not contain previous instance data (this._i)')
162
- this._i = 97 // 'a'
163
- } else
164
- this._i++
165
- var b = new Buffer(chunk.length)
166
- for (var i = 0; i < chunk.length; i++)
167
- b[i] = this._i
168
- this.push(b)
169
- callback()
170
- })
171
-
172
- var th2 = Th2()
173
-
174
- th2.pipe(bl(function (err, b) {
175
- var s = b.toString('ascii')
176
- t.equal('aaaaaaaaaabbbbbcccccccccc', s, 'got transformed string')
177
-
178
- var newInstance = Th2()
179
- newInstance.pipe(bl(function (err, b) {
180
- var s = b.toString('ascii')
181
- t.equal('aaaaaaabbbbccccccc', s, 'got transformed string')
182
- }))
183
-
184
- newInstance.write(crypto.randomBytes(7))
185
- newInstance.write(crypto.randomBytes(4))
186
- newInstance.write(crypto.randomBytes(7))
187
- newInstance.end()
188
- }))
189
-
190
- th2.write(crypto.randomBytes(10))
191
- th2.write(crypto.randomBytes(5))
192
- th2.write(crypto.randomBytes(10))
193
- th2.end()
194
- })
195
-
196
- test('object through ctor', function (t) {
197
- t.plan(3)
198
-
199
- var Th2 = through2.ctor({ objectMode: true}, function (chunk, enc, callback) {
200
- this.push({ out: chunk.in + 1 })
201
- callback()
202
- })
203
-
204
- var th2 = new Th2()
205
-
206
- var e = 0
207
- th2.on('data', function (o) {
208
- t.deepEqual(o, { out: e === 0 ? 102 : e == 1 ? 203 : -99 }, 'got transformed object')
209
- e++
210
- })
211
-
212
- th2.write({ in: 101 })
213
- th2.write({ in: 202 })
214
- th2.write({ in: -100 })
215
- th2.end()
216
- })
217
-
218
- test('pipeable object through ctor', function (t) {
219
- t.plan(4)
220
-
221
- var Th2 = through2.ctor({ objectMode: true}, function (record, enc, callback) {
222
- if (record.temp != null && record.unit == 'F') {
223
- record.temp = ( ( record.temp - 32 ) * 5 ) / 9
224
- record.unit = 'C'
225
- }
226
- this.push(record)
227
- callback()
228
- })
229
-
230
- var th2 = Th2()
231
-
232
- var expect = [-19, -40, 100, 22]
233
- th2.on('data', function (o) {
234
- t.deepEqual(o, { temp: expect.shift(), unit: 'C' }, 'got transformed object')
235
- })
236
-
237
- spigot({objectMode: true}, [
238
- {temp: -2.2, unit: 'F'},
239
- {temp: -40, unit: 'F'},
240
- {temp: 212, unit: 'F'},
241
- {temp: 22, unit: 'C'}
242
- ]).pipe(th2)
243
- })
244
-
245
- test('object through ctor override', function (t) {
246
- t.plan(3)
247
-
248
- var Th2 = through2.ctor(function (chunk, enc, callback) {
249
- this.push({ out: chunk.in + 1 })
250
- callback()
251
- })
252
-
253
- var th2 = Th2({objectMode: true})
254
-
255
- var e = 0
256
- th2.on('data', function (o) {
257
- t.deepEqual(o, { out: e === 0 ? 102 : e == 1 ? 203 : -99 }, 'got transformed object')
258
- e++
259
- })
260
-
261
- th2.write({ in: 101 })
262
- th2.write({ in: 202 })
263
- th2.write({ in: -100 })
264
- th2.end()
265
- })
266
-
267
- test('object settings available in transform', function (t) {
268
- t.plan(6)
269
-
270
- var Th2 = through2.ctor({objectMode: true, peek: true}, function (chunk, enc, callback) {
271
- t.ok(this.options.peek, "reading options from inside _transform")
272
- this.push({ out: chunk.in + 1 })
273
- callback()
274
- })
275
-
276
- var th2 = Th2()
277
-
278
- var e = 0
279
- th2.on('data', function (o) {
280
- t.deepEqual(o, { out: e === 0 ? 102 : e == 1 ? 203 : -99 }, 'got transformed object')
281
- e++
282
- })
283
-
284
- th2.write({ in: 101 })
285
- th2.write({ in: 202 })
286
- th2.write({ in: -100 })
287
- th2.end()
288
- })
289
-
290
- test('object settings available in transform override', function (t) {
291
- t.plan(6)
292
-
293
- var Th2 = through2.ctor(function (chunk, enc, callback) {
294
- t.ok(this.options.peek, "reading options from inside _transform")
295
- this.push({ out: chunk.in + 1 })
296
- callback()
297
- })
298
-
299
- var th2 = Th2({objectMode: true, peek: true})
300
-
301
- var e = 0
302
- th2.on('data', function (o) {
303
- t.deepEqual(o, { out: e === 0 ? 102 : e == 1 ? 203 : -99 }, 'got transformed object')
304
- e++
305
- })
306
-
307
- th2.write({ in: 101 })
308
- th2.write({ in: 202 })
309
- th2.write({ in: -100 })
310
- th2.end()
311
- })
312
-
313
- test('object override extends options', function (t) {
314
- t.plan(6)
315
-
316
- var Th2 = through2.ctor({objectMode: true}, function (chunk, enc, callback) {
317
- t.ok(this.options.peek, "reading options from inside _transform")
318
- this.push({ out: chunk.in + 1 })
319
- callback()
320
- })
321
-
322
- var th2 = Th2({peek: true})
323
-
324
- var e = 0
325
- th2.on('data', function (o) {
326
- t.deepEqual(o, { out: e === 0 ? 102 : e == 1 ? 203 : -99 }, 'got transformed object')
327
- e++
328
- })
329
-
330
- th2.write({ in: 101 })
331
- th2.write({ in: 202 })
332
- th2.write({ in: -100 })
333
- th2.end()
334
- })
package/test/bench.js DELETED
@@ -1,42 +0,0 @@
1
- /*
2
- on rvagg@fletcher:
3
- @0.2.3: Ran 36719 iterations in 10000 ms
4
- */
5
-
6
- const through2 = require('../')
7
- , bl = require('bl')
8
- , crypto = require('crypto')
9
- , assert = require('assert')
10
-
11
- function run (callback) {
12
- var bufs = Array.apply(null, Array(10)).map(function () { return crypto.randomBytes(32) })
13
- , stream = through2(function (chunk, env, callback) {
14
- callback(null, chunk.toString('hex'))
15
- })
16
-
17
- stream.pipe(bl(function (err, data) {
18
- assert(!err)
19
- assert.equal(data.toString(), Buffer.concat(bufs).toString('hex'))
20
- callback()
21
- }))
22
-
23
- bufs.forEach(function (b) {
24
- stream.write(b)
25
- })
26
- stream.end()
27
- }
28
-
29
- var count = 0
30
- , start = Date.now()
31
-
32
- ;(function exec () {
33
- count++
34
- run(function () {
35
- if (Date.now() - start < 1000 * 10) {
36
- return setImmediate(exec)
37
- }
38
- console.log('Ran', count, 'iterations in', Date.now() - start, 'ms')
39
- })
40
- }())
41
-
42
- console.log('Running for ~10s')
package/test/sauce.js DELETED
@@ -1,38 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- const user = process.env.SAUCE_USER
4
- , key = process.env.SAUCE_KEY
5
- , path = require('path')
6
- , brtapsauce = require('brtapsauce')
7
- , testFile = path.join(__dirname, 'basic-test.js')
8
-
9
- , capabilities = [
10
- { browserName: 'chrome' , platform: 'Windows XP', version: '' }
11
- , { browserName: 'firefox' , platform: 'Windows 8' , version: '' }
12
- , { browserName: 'firefox' , platform: 'Windows XP', version: '4' }
13
- , { browserName: 'internet explorer' , platform: 'Windows 8' , version: '10' }
14
- , { browserName: 'internet explorer' , platform: 'Windows 7' , version: '9' }
15
- , { browserName: 'internet explorer' , platform: 'Windows 7' , version: '8' }
16
- , { browserName: 'internet explorer' , platform: 'Windows XP', version: '7' }
17
- , { browserName: 'internet explorer' , platform: 'Windows XP', version: '6' }
18
- , { browserName: 'safari' , platform: 'Windows 7' , version: '5' }
19
- , { browserName: 'safari' , platform: 'OS X 10.8' , version: '6' }
20
- , { browserName: 'opera' , platform: 'Windows 7' , version: '' }
21
- , { browserName: 'opera' , platform: 'Windows 7' , version: '11' }
22
- , { browserName: 'ipad' , platform: 'OS X 10.8' , version: '6' }
23
- , { browserName: 'android' , platform: 'Linux' , version: '4.0', 'device-type': 'tablet' }
24
- ]
25
-
26
- if (!user)
27
- throw new Error('Must set a SAUCE_USER env var')
28
- if (!key)
29
- throw new Error('Must set a SAUCE_KEY env var')
30
-
31
- brtapsauce({
32
- name : 'Traversty'
33
- , user : user
34
- , key : key
35
- , brsrc : testFile
36
- , capabilities : capabilities
37
- , options : { timeout: 60 * 6 }
38
- })
package/test/test.js DELETED
@@ -1,9 +0,0 @@
1
- require('./basic-test')
2
-
3
- if (!process.env.SAUCE_KEY || !process.env.SAUCE_USER)
4
- return console.log('SAUCE_KEY and/or SAUCE_USER not set, not running sauce tests')
5
-
6
- if (!/v0\.10/.test(process.version))
7
- return console.log('Not Node v0.10.x, not running sauce tests')
8
-
9
- require('./sauce.js')