through2 0.4.2 → 0.6.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 (3) hide show
  1. package/README.md +3 -1
  2. package/package.json +6 -7
  3. package/through2.js +22 -4
package/README.md CHANGED
@@ -100,7 +100,9 @@ The `transformFunction` must have the following signature: `function (chunk, enc
100
100
 
101
101
  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.
102
102
 
103
- If you **do not provide a `transformFunction`** then you will get a simple simple pass-through stream.
103
+ Alternatively, you may use `callback(err, chunk)` as shorthand for emitting a single chunk or an error.
104
+
105
+ If you **do not provide a `transformFunction`** then you will get a simple pass-through stream.
104
106
 
105
107
  ### flushFunction
106
108
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "through2",
3
- "version": "0.4.2",
3
+ "version": "0.6.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,13 +20,12 @@
20
20
  "author": "Rod Vagg <r@va.gg> (https://github.com/rvagg)",
21
21
  "license": "MIT",
22
22
  "dependencies": {
23
- "readable-stream": "~1.0.17",
24
- "xtend": "~2.1.1"
23
+ "readable-stream": ">=1.0.27-1 <1.1.0-0",
24
+ "xtend": ">=4.0.0 <4.1.0-0"
25
25
  },
26
26
  "devDependencies": {
27
- "tape": "~2.3.0",
28
- "bl": "~0.6.0",
29
- "stream-spigot": "~3.0.1",
30
- "brtapsauce": "~0.2.2"
27
+ "bl": ">=0.9.0 <0.10.0-0",
28
+ "stream-spigot": ">=3.0.4 <3.1.0-0",
29
+ "tape": ">=2.14.0 <2.15.0-0"
31
30
  }
32
31
  }
package/through2.js CHANGED
@@ -2,6 +2,24 @@ var Transform = require('readable-stream/transform')
2
2
  , inherits = require('util').inherits
3
3
  , xtend = require('xtend')
4
4
 
5
+ function DestroyableTransform(opts) {
6
+ Transform.call(this, opts)
7
+ this._destroyed = false
8
+ }
9
+
10
+ inherits(DestroyableTransform, Transform)
11
+
12
+ DestroyableTransform.prototype.destroy = function(err) {
13
+ if (this._destroyed) return
14
+ this._destroyed = true
15
+
16
+ var self = this
17
+ process.nextTick(function() {
18
+ if (err)
19
+ self.emit('error', err)
20
+ self.emit('close')
21
+ })
22
+ }
5
23
 
6
24
  // a noop _transform function
7
25
  function noop (chunk, enc, callback) {
@@ -32,7 +50,7 @@ function through2 (construct) {
32
50
 
33
51
  // main export, just make me a transform stream!
34
52
  module.exports = through2(function (options, transform, flush) {
35
- var t2 = new Transform(options)
53
+ var t2 = new DestroyableTransform(options)
36
54
 
37
55
  t2._transform = transform
38
56
 
@@ -52,10 +70,10 @@ module.exports.ctor = through2(function (options, transform, flush) {
52
70
 
53
71
  this.options = xtend(options, override)
54
72
 
55
- Transform.call(this, this.options)
73
+ DestroyableTransform.call(this, this.options)
56
74
  }
57
75
 
58
- inherits(Through2, Transform)
76
+ inherits(Through2, DestroyableTransform)
59
77
 
60
78
  Through2.prototype._transform = transform
61
79
 
@@ -67,7 +85,7 @@ module.exports.ctor = through2(function (options, transform, flush) {
67
85
 
68
86
 
69
87
  module.exports.obj = through2(function (options, transform, flush) {
70
- var t2 = new Transform(xtend({ objectMode: true }, options))
88
+ var t2 = new DestroyableTransform(xtend({ objectMode: true, highWaterMark: 16 }, options))
71
89
 
72
90
  t2._transform = transform
73
91