[Pkg-javascript-commits] [node-through2] 01/21: New upstream version 2.0.1
Jérémy Lal
kapouer at moszumanska.debian.org
Mon Nov 28 23:35:19 UTC 2016
This is an automated email from the git hooks/post-receive script.
kapouer pushed a commit to branch master
in repository node-through2.
commit eeb6892dc654a80d3da0ea6cbbcdfdd609d2b514
Author: Jérémy Lal <kapouer at melix.org>
Date: Sun Nov 27 18:39:06 2016 +0100
New upstream version 2.0.1
---
.gitignore | 1 +
.travis.yml | 1 -
README.md | 55 +++++++++++++++++++++++--------------------------------
package.json | 18 ++++++++----------
test/sauce.js | 18 ++++++++++++------
5 files changed, 44 insertions(+), 49 deletions(-)
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..b512c09
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+node_modules
\ No newline at end of file
diff --git a/.travis.yml b/.travis.yml
index 12b1a31..fdaa286 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,6 +1,5 @@
language: node_js
node_js:
-- '0.8'
- '0.10'
- '0.11'
branches:
diff --git a/README.md b/README.md
index ec74569..c84b346 100644
--- a/README.md
+++ b/README.md
@@ -1,34 +1,16 @@
# through2
-<!--
-
-soon ...
-
-[![Build Status](https://secure.travis-ci.org/rvagg/through2.png)](http://travis-ci.org/rvagg/through2)
-
-[![Build Status](https://saucelabs.com/browser-matrix/through2-sauce.svg)](https://travis-ci.org/rvagg/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
-
-[![david-dm](https://david-dm.org/rvagg/through2.png)](https://david-dm.org/rvagg/through2/)
-[![david-dm](https://david-dm.org/rvagg/through2/dev-status.png)](https://david-dm.org/rvagg/through2#info=devDependencies/)
--->
+[![NPM](https://nodei.co/npm/through2.png?downloads&downloadRank)](https://nodei.co/npm/through2/)
**A tiny wrapper around Node streams.Transform (Streams2) to avoid explicit subclassing noise**
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).
+Note: As 2.x.x this module starts using **Streams3** instead of Stream2. To continue using a Streams2 version use `npm install through2 at 0` to fetch the latest version of 0.x.x. More information about Streams2 vs Streams3 and recommendations see the article **[Why I don't use Node's core 'stream' module](http://r.va.gg/2014/06/why-i-dont-use-nodes-core-stream-module.html)**.
```js
fs.createReadStream('ex.txt')
.pipe(through2(function (chunk, enc, callback) {
-
for (var i = 0; i < chunk.length; i++)
if (chunk[i] == 97)
chunk[i] = 122 // swap 'a' for 'z'
@@ -36,7 +18,6 @@ fs.createReadStream('ex.txt')
this.push(chunk)
callback()
-
}))
.pipe(fs.createWriteStream('out.txt'))
```
@@ -49,17 +30,14 @@ var all = []
fs.createReadStream('data.csv')
.pipe(csv2())
.pipe(through2.obj(function (chunk, enc, callback) {
-
var data = {
name : chunk[0]
, address : chunk[3]
, phone : chunk[10]
}
-
this.push(data)
callback()
-
}))
.on('data', function (data) {
all.push(data)
@@ -85,12 +63,12 @@ The `options` argument is first, unlike standard convention, because if I'm pass
```js
fs.createReadStream('/tmp/important.dat')
- .pipe(through2({ objectMode: true, allowHalfOpen: false }, function (chunk, enc, cb) {
-
- this.push(new Buffer('wut?'))
- cb()
-
- })
+ .pipe(through2({ objectMode: true, allowHalfOpen: false },
+ function (chunk, enc, cb) {
+ cb(null, 'wut?') // note we can use the second argument on the callback
+ // to provide data as an alternative to this.push('wut?')
+ }
+ )
.pipe(fs.createWriteStream('/tmp/wut.txt'))
```
@@ -108,13 +86,25 @@ If you **do not provide a `transformFunction`** then you will get a simple pass-
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.
+```js
+fs.createReadStream('/tmp/important.dat')
+ .pipe(through2(
+ function (chunk, enc, cb) { cb(null, chunk) }, // transform is a noop
+ function (cb) { // flush function
+ this.push('tacking on an extra buffer to the end');
+ cb();
+ }
+ ))
+ .pipe(fs.createWriteStream('/tmp/wut.txt'));
+```
+
<b><code>through2.ctor([ options, ] transformFunction[, flushFunction ])</code></b>
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.
```js
var FToC = through2.ctor({objectMode: true}, function (record, encoding, callback) {
- if (record.temp != null && record.unit = "F") {
+ if (record.temp != null && record.unit == "F") {
record.temp = ( ( record.temp - 32 ) * 5 ) / 9
record.unit = "C"
}
@@ -136,7 +126,8 @@ var converter = FToC({objectMode: true})
- [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.
+ - the [mississippi stream utility collection](https://github.com/maxogden/mississippi) includes `through2` as well as many more useful stream modules similar to this one
## 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.
+**through2** is Copyright (c) 2013 Rod Vagg [@rvagg](https://twitter.com/rvagg) and licensed under the MIT license. 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 97e4829..c7afac7 100644
--- a/package.json
+++ b/package.json
@@ -1,10 +1,10 @@
{
"name": "through2",
- "version": "1.1.1",
+ "version": "2.0.1",
"description": "A tiny wrapper around Node streams2 Transform to avoid explicit subclassing noise",
"main": "through2.js",
"scripts": {
- "test": "node test/test.js",
+ "test": "node test/test.js | faucet",
"test-local": "brtapsauce-local test/basic-test.js"
},
"repository": {
@@ -20,15 +20,13 @@
"author": "Rod Vagg <r at va.gg> (https://github.com/rvagg)",
"license": "MIT",
"dependencies": {
- "readable-stream": ">=1.1.13-1 <1.2.0-0",
- "xtend": ">=4.0.0 <4.1.0-0"
+ "readable-stream": "~2.0.0",
+ "xtend": "~4.0.0"
},
"devDependencies": {
- "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"
+ "bl": "~0.9.4",
+ "faucet": "0.0.1",
+ "stream-spigot": "~3.0.5",
+ "tape": "~4.0.0"
}
}
diff --git a/test/sauce.js b/test/sauce.js
index a6d2862..7266a6f 100644
--- a/test/sauce.js
+++ b/test/sauce.js
@@ -1,12 +1,18 @@
#!/usr/bin/env node
-const user = process.env.SAUCE_USER
- , key = process.env.SAUCE_KEY
- , path = require('path')
- , brtapsauce = require('brtapsauce')
- , testFile = path.join(__dirname, 'basic-test.js')
+var user = process.env.SAUCE_USER
+ , key = process.env.SAUCE_KEY
+ , path = require('path')
+ , brtapsauce
+ , testFile = path.join(__dirname, 'basic-test.js')
- , capabilities = [
+try {
+ brtapsauce = require('brtapsauce')
+} catch (e) {
+ return
+}
+
+const capabilities = [
{ browserName: 'chrome' , platform: 'Windows XP', version: '' }
, { browserName: 'firefox' , platform: 'Windows 8' , version: '' }
, { browserName: 'firefox' , platform: 'Windows XP', version: '4' }
--
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