[Pkg-javascript-commits] [node-through2] 02/08: Imported Upstream version 1.1.1
Leo Iannacone
l3on-guest at moszumanska.debian.org
Sat Oct 11 17:26:50 UTC 2014
This is an automated email from the git hooks/post-receive script.
l3on-guest pushed a commit to branch master
in repository node-through2.
commit 09ec037fffb65b70515a0921d87492dafc9f70fa
Author: Leo Iannacone <l3on at ubuntu.com>
Date: Sat Oct 11 19:04:09 2014 +0200
Imported Upstream version 1.1.1
---
.npmignore | 3 +++
README.md | 21 ++++++++++++++++-----
package.json | 13 ++++++-------
test/basic-test.js | 27 +++++++++++++++++++++++++++
through2.js | 26 ++++++++++++++++++++++----
5 files changed, 74 insertions(+), 16 deletions(-)
diff --git a/.npmignore b/.npmignore
new file mode 100644
index 0000000..1e1dcab
--- /dev/null
+++ b/.npmignore
@@ -0,0 +1,3 @@
+test
+.jshintrc
+.travis.yml
\ No newline at end of file
diff --git a/README.md b/README.md
index c9388b3..ec74569 100644
--- a/README.md
+++ b/README.md
@@ -10,7 +10,7 @@ soon ...
-->
-[![NPM](https://nodei.co/npm/through2.png?compact=true)](https://nodei.co/npm/through2/)
+[![NPM](https://nodei.co/npm/through2.png?compact=true)](https://nodei.co/npm/through2/)
<!--
not happy with these, we need to peg to readable-stream at 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 at 1.0.x so it'll always re
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) { ... })`.
+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 at 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).
+
```js
fs.createReadStream('ex.txt')
.pipe(through2(function (chunk, enc, callback) {
@@ -32,7 +34,7 @@ fs.createReadStream('ex.txt')
chunk[i] = 122 // swap 'a' for 'z'
this.push(chunk)
-
+
callback()
}))
@@ -53,9 +55,9 @@ fs.createReadStream('data.csv')
, address : chunk[3]
, phone : chunk[10]
}
-
+
this.push(data)
-
+
callback()
}))
@@ -98,7 +100,9 @@ The `transformFunction` must have the following signature: `function (chunk, enc
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.
-If you **do not provide a `transformFunction`** then you will get a simple simple pass-through stream.
+Alternatively, you may use `callback(err, chunk)` as shorthand for emitting a single chunk or an error.
+
+If you **do not provide a `transformFunction`** then you will get a simple pass-through stream.
### flushFunction
@@ -126,6 +130,13 @@ var converter = FToC()
var converter = FToC({objectMode: true})
```
+## See Also
+
+ - [through2-map](https://github.com/brycebaril/through2-map) - Array.prototype.map analog for streams.
+ - [through2-filter](https://github.com/brycebaril/through2-filter) - Array.prototype.filter analog for streams.
+ - [through2-reduce](https://github.com/brycebaril/through2-reduce) - Array.prototype.reduce analog for streams.
+ - [through2-spy](https://github.com/brycebaril/through2-spy) - Wrapper for simple stream.PassThrough spies.
+
## License
**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.
diff --git a/package.json b/package.json
index e9e9610..97e4829 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "through2",
- "version": "1.0.0",
+ "version": "1.1.1",
"description": "A tiny wrapper around Node streams2 Transform to avoid explicit subclassing noise",
"main": "through2.js",
"scripts": {
@@ -20,14 +20,13 @@
"author": "Rod Vagg <r at va.gg> (https://github.com/rvagg)",
"license": "MIT",
"dependencies": {
- "readable-stream": "~1.1.10",
- "xtend": "~2.1.1"
+ "readable-stream": ">=1.1.13-1 <1.2.0-0",
+ "xtend": ">=4.0.0 <4.1.0-0"
},
"devDependencies": {
- "tape": "~2.3.0",
- "bl": "~0.6.0",
- "stream-spigot": "~3.0.1",
- "brtapsauce": "~0.2.2"
+ "bl": ">=0.9.0 <0.10.0-0",
+ "stream-spigot": ">=3.0.4 <3.1.0-0",
+ "tape": ">=2.14.0 <2.15.0-0"
},
"publishConfig": {
"tag": "1.0"
diff --git a/test/basic-test.js b/test/basic-test.js
index 9d137c7..63d2542 100644
--- a/test/basic-test.js
+++ b/test/basic-test.js
@@ -331,4 +331,31 @@ test('object override extends options', function (t) {
th2.write({ in: 202 })
th2.write({ in: -100 })
th2.end()
+})
+
+test('can be destroyed', function(t) {
+ t.plan(1)
+
+ var th = through2()
+
+ th.on('close', function() {
+ t.ok(true, 'shoud emit close')
+ t.end()
+ })
+
+ th.destroy()
+})
+
+test('can be destroyed twice', function(t) {
+ t.plan(1)
+
+ var th = through2()
+
+ th.on('close', function() {
+ t.ok(true, 'shoud emit close')
+ t.end()
+ })
+
+ th.destroy()
+ th.destroy()
})
\ No newline at end of file
diff --git a/through2.js b/through2.js
index c110484..5b7a880 100644
--- a/through2.js
+++ b/through2.js
@@ -2,6 +2,24 @@ var Transform = require('readable-stream/transform')
, inherits = require('util').inherits
, xtend = require('xtend')
+function DestroyableTransform(opts) {
+ Transform.call(this, opts)
+ this._destroyed = false
+}
+
+inherits(DestroyableTransform, Transform)
+
+DestroyableTransform.prototype.destroy = function(err) {
+ if (this._destroyed) return
+ this._destroyed = true
+
+ var self = this
+ process.nextTick(function() {
+ if (err)
+ self.emit('error', err)
+ self.emit('close')
+ })
+}
// a noop _transform function
function noop (chunk, enc, callback) {
@@ -32,7 +50,7 @@ function through2 (construct) {
// main export, just make me a transform stream!
module.exports = through2(function (options, transform, flush) {
- var t2 = new Transform(options)
+ var t2 = new DestroyableTransform(options)
t2._transform = transform
@@ -52,10 +70,10 @@ module.exports.ctor = through2(function (options, transform, flush) {
this.options = xtend(options, override)
- Transform.call(this, this.options)
+ DestroyableTransform.call(this, this.options)
}
- inherits(Through2, Transform)
+ inherits(Through2, DestroyableTransform)
Through2.prototype._transform = transform
@@ -67,7 +85,7 @@ module.exports.ctor = through2(function (options, transform, flush) {
module.exports.obj = through2(function (options, transform, flush) {
- var t2 = new Transform(xtend({ objectMode: true }, options))
+ var t2 = new DestroyableTransform(xtend({ objectMode: true, highWaterMark: 16 }, options))
t2._transform = transform
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-through2.git
More information about the Pkg-javascript-commits
mailing list