node_task 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/lib/node_task/index.js +28 -21
  3. data/lib/node_task/node_modules/ndjson/cli.js +23 -0
  4. data/lib/node_task/node_modules/ndjson/collaborators.md +7 -0
  5. data/lib/node_task/node_modules/ndjson/index.js +30 -0
  6. data/lib/node_task/node_modules/ndjson/node_modules/minimist/example/parse.js +2 -0
  7. data/lib/node_task/node_modules/ndjson/node_modules/minimist/index.js +236 -0
  8. data/lib/node_task/node_modules/ndjson/node_modules/minimist/package.json +71 -0
  9. data/lib/node_task/node_modules/ndjson/node_modules/minimist/readme.markdown +91 -0
  10. data/lib/node_task/node_modules/ndjson/node_modules/minimist/test/all_bool.js +32 -0
  11. data/lib/node_task/node_modules/ndjson/node_modules/minimist/test/bool.js +166 -0
  12. data/lib/node_task/node_modules/ndjson/node_modules/minimist/test/dash.js +31 -0
  13. data/lib/node_task/node_modules/ndjson/node_modules/minimist/test/default_bool.js +35 -0
  14. data/lib/node_task/node_modules/ndjson/node_modules/minimist/test/dotted.js +22 -0
  15. data/lib/node_task/node_modules/ndjson/node_modules/minimist/test/kv_short.js +16 -0
  16. data/lib/node_task/node_modules/ndjson/node_modules/minimist/test/long.js +31 -0
  17. data/lib/node_task/node_modules/ndjson/node_modules/minimist/test/num.js +36 -0
  18. data/lib/node_task/node_modules/ndjson/node_modules/minimist/test/parse.js +197 -0
  19. data/lib/node_task/node_modules/ndjson/node_modules/minimist/test/parse_modified.js +9 -0
  20. data/lib/node_task/node_modules/ndjson/node_modules/minimist/test/short.js +67 -0
  21. data/lib/node_task/node_modules/ndjson/node_modules/minimist/test/stop_early.js +15 -0
  22. data/lib/node_task/node_modules/ndjson/node_modules/minimist/test/unknown.js +102 -0
  23. data/lib/node_task/node_modules/ndjson/node_modules/minimist/test/whitespace.js +8 -0
  24. data/lib/node_task/node_modules/ndjson/node_modules/split2/README.md +74 -0
  25. data/lib/node_task/node_modules/ndjson/node_modules/split2/index.js +83 -0
  26. data/lib/node_task/node_modules/ndjson/node_modules/split2/package.json +55 -0
  27. data/lib/node_task/node_modules/ndjson/node_modules/split2/test.js +149 -0
  28. data/lib/node_task/node_modules/ndjson/node_modules/through2/README.md +132 -0
  29. data/lib/node_task/node_modules/ndjson/node_modules/through2/node_modules/readable-stream/README.md +15 -0
  30. data/lib/node_task/node_modules/ndjson/node_modules/through2/node_modules/readable-stream/duplex.js +1 -0
  31. data/lib/node_task/node_modules/ndjson/node_modules/through2/node_modules/readable-stream/lib/_stream_duplex.js +89 -0
  32. data/lib/node_task/node_modules/ndjson/node_modules/through2/node_modules/readable-stream/lib/_stream_passthrough.js +46 -0
  33. data/lib/node_task/node_modules/ndjson/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js +982 -0
  34. data/lib/node_task/node_modules/ndjson/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js +210 -0
  35. data/lib/node_task/node_modules/ndjson/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js +386 -0
  36. data/lib/node_task/node_modules/ndjson/node_modules/through2/node_modules/readable-stream/node_modules/core-util-is/README.md +3 -0
  37. data/lib/node_task/node_modules/ndjson/node_modules/through2/node_modules/readable-stream/node_modules/core-util-is/float.patch +604 -0
  38. data/lib/node_task/node_modules/ndjson/node_modules/through2/node_modules/readable-stream/node_modules/core-util-is/lib/util.js +107 -0
  39. data/lib/node_task/node_modules/ndjson/node_modules/through2/node_modules/readable-stream/node_modules/core-util-is/package.json +53 -0
  40. data/lib/node_task/node_modules/ndjson/node_modules/through2/node_modules/readable-stream/node_modules/core-util-is/util.js +106 -0
  41. data/lib/node_task/node_modules/ndjson/node_modules/through2/node_modules/readable-stream/node_modules/inherits/README.md +42 -0
  42. data/lib/node_task/node_modules/ndjson/node_modules/through2/node_modules/readable-stream/node_modules/inherits/inherits.js +1 -0
  43. data/lib/node_task/node_modules/ndjson/node_modules/through2/node_modules/readable-stream/node_modules/inherits/inherits_browser.js +23 -0
  44. data/lib/node_task/node_modules/ndjson/node_modules/through2/node_modules/readable-stream/node_modules/inherits/package.json +50 -0
  45. data/lib/node_task/node_modules/ndjson/node_modules/through2/node_modules/readable-stream/node_modules/inherits/test.js +25 -0
  46. data/lib/node_task/node_modules/ndjson/node_modules/through2/node_modules/readable-stream/node_modules/isarray/README.md +54 -0
  47. data/lib/node_task/node_modules/ndjson/node_modules/through2/node_modules/readable-stream/node_modules/isarray/build/build.js +209 -0
  48. data/lib/node_task/node_modules/ndjson/node_modules/through2/node_modules/readable-stream/node_modules/isarray/component.json +19 -0
  49. data/lib/node_task/node_modules/ndjson/node_modules/through2/node_modules/readable-stream/node_modules/isarray/index.js +3 -0
  50. data/lib/node_task/node_modules/ndjson/node_modules/through2/node_modules/readable-stream/node_modules/isarray/package.json +53 -0
  51. data/lib/node_task/node_modules/ndjson/node_modules/through2/node_modules/readable-stream/node_modules/string_decoder/README.md +7 -0
  52. data/lib/node_task/node_modules/ndjson/node_modules/through2/node_modules/readable-stream/node_modules/string_decoder/index.js +221 -0
  53. data/lib/node_task/node_modules/ndjson/node_modules/through2/node_modules/readable-stream/node_modules/string_decoder/package.json +54 -0
  54. data/lib/node_task/node_modules/ndjson/node_modules/through2/node_modules/readable-stream/package.json +70 -0
  55. data/lib/node_task/node_modules/ndjson/node_modules/through2/node_modules/readable-stream/passthrough.js +1 -0
  56. data/lib/node_task/node_modules/ndjson/node_modules/through2/node_modules/readable-stream/readable.js +8 -0
  57. data/lib/node_task/node_modules/ndjson/node_modules/through2/node_modules/readable-stream/transform.js +1 -0
  58. data/lib/node_task/node_modules/ndjson/node_modules/through2/node_modules/readable-stream/writable.js +1 -0
  59. data/lib/node_task/node_modules/ndjson/node_modules/through2/node_modules/xtend/README.md +32 -0
  60. data/lib/node_task/node_modules/ndjson/node_modules/through2/node_modules/xtend/immutable.js +17 -0
  61. data/lib/node_task/node_modules/ndjson/node_modules/through2/node_modules/xtend/mutable.js +15 -0
  62. data/lib/node_task/node_modules/ndjson/node_modules/through2/node_modules/xtend/package.json +88 -0
  63. data/lib/node_task/node_modules/ndjson/node_modules/through2/node_modules/xtend/test.js +63 -0
  64. data/lib/node_task/node_modules/ndjson/node_modules/through2/package.json +65 -0
  65. data/lib/node_task/node_modules/ndjson/node_modules/through2/through2.js +96 -0
  66. data/lib/node_task/node_modules/ndjson/package.json +64 -0
  67. data/lib/node_task/node_modules/ndjson/readme.md +55 -0
  68. data/lib/node_task/node_modules/ndjson/test.js +73 -0
  69. data/lib/node_task/node_task.rb +6 -13
  70. data/lib/node_task/package.json +2 -3
  71. metadata +69 -3
@@ -0,0 +1,102 @@
1
+ var parse = require('../');
2
+ var test = require('tape');
3
+
4
+ test('boolean and alias is not unknown', function (t) {
5
+ var unknown = [];
6
+ function unknownFn(arg) {
7
+ unknown.push(arg);
8
+ return false;
9
+ }
10
+ var aliased = [ '-h', 'true', '--derp', 'true' ];
11
+ var regular = [ '--herp', 'true', '-d', 'true' ];
12
+ var opts = {
13
+ alias: { h: 'herp' },
14
+ boolean: 'h',
15
+ unknown: unknownFn
16
+ };
17
+ var aliasedArgv = parse(aliased, opts);
18
+ var propertyArgv = parse(regular, opts);
19
+
20
+ t.same(unknown, ['--derp', '-d']);
21
+ t.end();
22
+ });
23
+
24
+ test('flag boolean true any double hyphen argument is not unknown', function (t) {
25
+ var unknown = [];
26
+ function unknownFn(arg) {
27
+ unknown.push(arg);
28
+ return false;
29
+ }
30
+ var argv = parse(['--honk', '--tacos=good', 'cow', '-p', '55'], {
31
+ boolean: true,
32
+ unknown: unknownFn
33
+ });
34
+ t.same(unknown, ['--tacos=good', 'cow', '-p']);
35
+ t.same(argv, {
36
+ honk: true,
37
+ _: []
38
+ });
39
+ t.end();
40
+ });
41
+
42
+ test('string and alias is not unknown', function (t) {
43
+ var unknown = [];
44
+ function unknownFn(arg) {
45
+ unknown.push(arg);
46
+ return false;
47
+ }
48
+ var aliased = [ '-h', 'hello', '--derp', 'goodbye' ];
49
+ var regular = [ '--herp', 'hello', '-d', 'moon' ];
50
+ var opts = {
51
+ alias: { h: 'herp' },
52
+ string: 'h',
53
+ unknown: unknownFn
54
+ };
55
+ var aliasedArgv = parse(aliased, opts);
56
+ var propertyArgv = parse(regular, opts);
57
+
58
+ t.same(unknown, ['--derp', '-d']);
59
+ t.end();
60
+ });
61
+
62
+ test('default and alias is not unknown', function (t) {
63
+ var unknown = [];
64
+ function unknownFn(arg) {
65
+ unknown.push(arg);
66
+ return false;
67
+ }
68
+ var aliased = [ '-h', 'hello' ];
69
+ var regular = [ '--herp', 'hello' ];
70
+ var opts = {
71
+ default: { 'h': 'bar' },
72
+ alias: { 'h': 'herp' },
73
+ unknown: unknownFn
74
+ };
75
+ var aliasedArgv = parse(aliased, opts);
76
+ var propertyArgv = parse(regular, opts);
77
+
78
+ t.same(unknown, []);
79
+ t.end();
80
+ unknownFn(); // exercise fn for 100% coverage
81
+ });
82
+
83
+ test('value following -- is not unknown', function (t) {
84
+ var unknown = [];
85
+ function unknownFn(arg) {
86
+ unknown.push(arg);
87
+ return false;
88
+ }
89
+ var aliased = [ '--bad', '--', 'good', 'arg' ];
90
+ var opts = {
91
+ '--': true,
92
+ unknown: unknownFn
93
+ };
94
+ var argv = parse(aliased, opts);
95
+
96
+ t.same(unknown, ['--bad']);
97
+ t.same(argv, {
98
+ '--': ['good', 'arg'],
99
+ '_': []
100
+ })
101
+ t.end();
102
+ });
@@ -0,0 +1,8 @@
1
+ var parse = require('../');
2
+ var test = require('tape');
3
+
4
+ test('whitespace should be whitespace' , function (t) {
5
+ t.plan(1);
6
+ var x = parse([ '-x', '\t' ]).x;
7
+ t.equal(x, '\t');
8
+ });
@@ -0,0 +1,74 @@
1
+ # Split2(matcher, mapper, options)
2
+
3
+ [![build status](https://secure.travis-ci.org/mcollina/split2.png)](http://travis-ci.org/mcollina/split2)
4
+
5
+ Break up a stream and reassemble it so that each line is a chunk.
6
+ `split2` is inspired by [@dominictarr](https://github.com/dominictarr) [`split`](https://github.com/dominictarr) module,
7
+ and it is totally API compatible with it.
8
+ However, it is based on [`through2`](https://github.com/rvagg/through2) by [@rvagg](https://github.com/rvagg) and it is fully based on Stream2.
9
+
10
+ `matcher` may be a `String`, or a `RegExp`. Example, read every line in a file ...
11
+
12
+ ``` js
13
+ fs.createReadStream(file)
14
+ .pipe(split2())
15
+ .on('data', function (line) {
16
+ //each chunk now is a seperate line!
17
+ })
18
+
19
+ ```
20
+
21
+ `split` takes the same arguments as `string.split` except it defaults to '/\r?\n/' instead of ',', and the optional `limit` paremeter is ignored.
22
+ [String#split](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/String/split)
23
+
24
+ `split` takes an optional options object on it's third argument, which
25
+ is directly passed as a
26
+ [Transform](http://nodejs.org/api/stream.html#stream_class_stream_transform_1)
27
+ option.
28
+
29
+ Calling `.destroy` will make the stream emit `close`. Use this to perform cleanup logic
30
+
31
+ ``` js
32
+ var splitFile = function(filename) {
33
+ var file = fs.createReadStream(filename)
34
+
35
+ return file
36
+ .pipe(split2())
37
+ .on('close', function() {
38
+ // destroy the file stream in case the split stream was destroyed
39
+ file.destroy()
40
+ })
41
+ }
42
+
43
+ var stream = splitFile('my-file.txt')
44
+
45
+ stream.destroy() // will destroy the input file stream
46
+ ```
47
+
48
+ # NDJ - Newline Delimited Json
49
+
50
+ `split2` accepts a function which transforms each line.
51
+
52
+ ``` js
53
+ fs.createReadStream(file)
54
+ .pipe(split2(JSON.parse))
55
+ .on('data', function (obj) {
56
+ //each chunk now is a a js object
57
+ })
58
+ ```
59
+
60
+ # License
61
+
62
+ Copyright (c) 2014, Matteo Collina <hello@matteocollina.com>
63
+
64
+ Permission to use, copy, modify, and/or distribute this software for any
65
+ purpose with or without fee is hereby granted, provided that the above
66
+ copyright notice and this permission notice appear in all copies.
67
+
68
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
69
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
70
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
71
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
72
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
73
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
74
+ IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
@@ -0,0 +1,83 @@
1
+ /*
2
+ Copyright (c) 2014, Matteo Collina <hello@matteocollina.com>
3
+
4
+ Permission to use, copy, modify, and/or distribute this software for any
5
+ purpose with or without fee is hereby granted, provided that the above
6
+ copyright notice and this permission notice appear in all copies.
7
+
8
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
14
+ IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
+ */
16
+
17
+ 'use strict';
18
+
19
+ var through = require('through2')
20
+
21
+ function transform(chunk, enc, cb) {
22
+ var list = chunk.toString('utf8').split(this.matcher)
23
+ , remaining = list.pop()
24
+ , i
25
+
26
+ if (list.length >= 1) {
27
+ push(this, this.mapper((this._last + list.shift())))
28
+ } else {
29
+ remaining = this._last + remaining
30
+ }
31
+
32
+ for (i = 0; i < list.length; i++) {
33
+ push(this, this.mapper(list[i]))
34
+ }
35
+
36
+ this._last = remaining
37
+
38
+ cb()
39
+ }
40
+
41
+ function flush(cb) {
42
+ if (this._last)
43
+ push(this, this.mapper(this._last))
44
+
45
+ cb()
46
+ }
47
+
48
+ function push(self, val) {
49
+ if (val !== undefined)
50
+ self.push(val)
51
+ }
52
+
53
+ function noop(incoming) {
54
+ return incoming
55
+ }
56
+
57
+ function split(matcher, mapper, options) {
58
+
59
+ if (typeof matcher === 'object' && !(matcher instanceof RegExp)) {
60
+ options = matcher
61
+ matcher = null
62
+ }
63
+
64
+ if (typeof matcher === 'function') {
65
+ mapper = matcher
66
+ matcher = null
67
+ }
68
+
69
+ options = options || {}
70
+
71
+ var stream = through(options, transform, flush)
72
+
73
+ // this stream is in objectMode only in the readable part
74
+ stream._readableState.objectMode = true;
75
+
76
+ stream._last = ''
77
+ stream.matcher = matcher || /\r?\n/
78
+ stream.mapper = mapper || noop
79
+
80
+ return stream
81
+ }
82
+
83
+ module.exports = split
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "split2",
3
+ "version": "0.2.1",
4
+ "description": "split a Text Stream into a Line Stream, using Stream 2",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "tap test.js"
8
+ },
9
+ "pre-commit": [
10
+ "test"
11
+ ],
12
+ "website": "https://github.com/mcollina/split2",
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/mcollina/split2.git"
16
+ },
17
+ "bugs": {
18
+ "url": "http://github.com/mcollina/split2/issues"
19
+ },
20
+ "author": {
21
+ "name": "Matteo Collina",
22
+ "email": "hello@matteocollina.com"
23
+ },
24
+ "license": "ISC",
25
+ "devDependencies": {
26
+ "tap": "~0.4.12",
27
+ "pre-commit": "0.0.9",
28
+ "callback-stream": "~1.0.2"
29
+ },
30
+ "dependencies": {
31
+ "through2": "~0.6.1"
32
+ },
33
+ "homepage": "https://github.com/mcollina/split2",
34
+ "_id": "split2@0.2.1",
35
+ "_shasum": "02ddac9adc03ec0bb78c1282ec079ca6e85ae900",
36
+ "_from": "split2@>=0.2.1 <0.3.0",
37
+ "_npmVersion": "1.4.9",
38
+ "_npmUser": {
39
+ "name": "matteo.collina",
40
+ "email": "hello@matteocollina.com"
41
+ },
42
+ "maintainers": [
43
+ {
44
+ "name": "matteo.collina",
45
+ "email": "hello@matteocollina.com"
46
+ }
47
+ ],
48
+ "dist": {
49
+ "shasum": "02ddac9adc03ec0bb78c1282ec079ca6e85ae900",
50
+ "tarball": "http://registry.npmjs.org/split2/-/split2-0.2.1.tgz"
51
+ },
52
+ "directories": {},
53
+ "_resolved": "http://registry.npmjs.org/split2/-/split2-0.2.1.tgz",
54
+ "readme": "ERROR: No README data found!"
55
+ }
@@ -0,0 +1,149 @@
1
+
2
+ var test = require('tap').test
3
+ , split = require('./')
4
+ , callback = require('callback-stream')
5
+ , strcb = callback.bind(null, { decodeStrings: false })
6
+ , objcb = callback.bind(null, { objectMode: true })
7
+
8
+ test('split two lines on end', function(t) {
9
+ t.plan(1)
10
+
11
+ var input = split()
12
+
13
+ input.pipe(strcb(function(err, list) {
14
+ t.deepEqual(list, ['hello', 'world'])
15
+ }))
16
+
17
+ input.end('hello\nworld')
18
+ })
19
+
20
+ test('split two lines on two writes', function(t) {
21
+ t.plan(1)
22
+
23
+ var input = split()
24
+
25
+ input.pipe(strcb(function(err, list) {
26
+ t.deepEqual(list, ['hello', 'world'])
27
+ }))
28
+
29
+ input.write('hello')
30
+ input.write('\nworld')
31
+ input.end()
32
+ })
33
+
34
+ test('accumulate multiple writes', function(t) {
35
+ t.plan(1)
36
+
37
+ var input = split()
38
+
39
+ input.pipe(strcb(function(err, list) {
40
+ t.deepEqual(list, ['helloworld'])
41
+ }))
42
+
43
+ input.write('hello')
44
+ input.write('world')
45
+ input.end()
46
+ })
47
+
48
+ test('split using a custom string matcher', function(t) {
49
+ t.plan(1)
50
+
51
+ var input = split('~')
52
+
53
+ input.pipe(strcb(function(err, list) {
54
+ t.deepEqual(list, ['hello', 'world'])
55
+ }))
56
+
57
+ input.end('hello~world')
58
+ })
59
+
60
+ test('split using a custom regexp matcher', function(t) {
61
+ t.plan(1)
62
+
63
+ var input = split(/~/)
64
+
65
+ input.pipe(strcb(function(err, list) {
66
+ t.deepEqual(list, ['hello', 'world'])
67
+ }))
68
+
69
+ input.end('hello~world')
70
+ })
71
+
72
+ test('support an option argument', function(t) {
73
+ t.plan(2)
74
+
75
+ var input = split({ highWatermark: 2 })
76
+
77
+ input.pipe(strcb(function(err, list) {
78
+ t.notOk(err, 'no errors')
79
+ t.deepEqual(list, ['hello', 'world'])
80
+ }))
81
+
82
+ input.end('hello\nworld')
83
+ })
84
+
85
+ test('support a mapper function', function(t) {
86
+ t.plan(2)
87
+
88
+ var a = { a: '42' }
89
+ , b = { b: '24' }
90
+ var input = split(JSON.parse)
91
+
92
+ input.pipe(objcb(function(err, list) {
93
+ t.notOk(err, 'no errors')
94
+ t.deepEqual(list, [a, b])
95
+ }))
96
+
97
+ input.write(JSON.stringify(a))
98
+ input.write('\n')
99
+ input.end(JSON.stringify(b))
100
+ })
101
+
102
+ test('split lines windows-style', function(t) {
103
+ t.plan(1)
104
+
105
+ var input = split()
106
+
107
+ input.pipe(strcb(function(err, list) {
108
+ t.deepEqual(list, ['hello', 'world'])
109
+ }))
110
+
111
+ input.end('hello\r\nworld')
112
+ })
113
+
114
+ test('splits a buffer', function(t) {
115
+ t.plan(1)
116
+
117
+ var input = split()
118
+
119
+ input.pipe(strcb(function(err, list) {
120
+ t.deepEqual(list, ['hello', 'world'])
121
+ }))
122
+
123
+ input.end(new Buffer('hello\nworld'))
124
+ })
125
+
126
+ test('do not end on undefined', function(t) {
127
+ t.plan(1)
128
+
129
+ var input = split(function(line) {})
130
+
131
+ input.pipe(strcb(function(err, list) {
132
+ t.deepEqual(list, [])
133
+ }))
134
+
135
+ input.end(new Buffer('hello\nworld'))
136
+ })
137
+
138
+ test('has destroy method', function(t) {
139
+ t.plan(1)
140
+
141
+ var input = split(function(line) {})
142
+
143
+ input.on('close', function() {
144
+ t.ok(true, 'close emitted')
145
+ t.end()
146
+ })
147
+
148
+ input.destroy()
149
+ })
@@ -0,0 +1,132 @@
1
+ # through2
2
+
3
+ [![NPM](https://nodei.co/npm/through2.png?downloads&downloadRank)](https://nodei.co/npm/through2/)
4
+
5
+ **A tiny wrapper around Node streams.Transform (Streams2) to avoid explicit subclassing noise**
6
+
7
+ 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) { ... })`.
8
+
9
+ 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 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)**.
10
+
11
+ ```js
12
+ fs.createReadStream('ex.txt')
13
+ .pipe(through2(function (chunk, enc, callback) {
14
+ for (var i = 0; i < chunk.length; i++)
15
+ if (chunk[i] == 97)
16
+ chunk[i] = 122 // swap 'a' for 'z'
17
+
18
+ this.push(chunk)
19
+
20
+ callback()
21
+ }))
22
+ .pipe(fs.createWriteStream('out.txt'))
23
+ ```
24
+
25
+ Or object streams:
26
+
27
+ ```js
28
+ var all = []
29
+
30
+ fs.createReadStream('data.csv')
31
+ .pipe(csv2())
32
+ .pipe(through2.obj(function (chunk, enc, callback) {
33
+ var data = {
34
+ name : chunk[0]
35
+ , address : chunk[3]
36
+ , phone : chunk[10]
37
+ }
38
+ this.push(data)
39
+
40
+ callback()
41
+ }))
42
+ .on('data', function (data) {
43
+ all.push(data)
44
+ })
45
+ .on('end', function () {
46
+ doSomethingSpecial(all)
47
+ })
48
+ ```
49
+
50
+ Note that `through2.obj(fn)` is a convenience wrapper around `through2({ objectMode: true }, fn)`.
51
+
52
+ ## API
53
+
54
+ <b><code>through2([ options, ] [ transformFunction ] [, flushFunction ])</code></b>
55
+
56
+ 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`).
57
+
58
+ ### options
59
+
60
+ The options argument is optional and is passed straight through to `stream.Transform`. So you can use `objectMode:true` if you are processing non-binary streams (or just use `through2.obj()`).
61
+
62
+ The `options` argument is first, unlike standard convention, because if I'm passing in an anonymous function then I'd prefer for the options argument to not get lost at the end of the call:
63
+
64
+ ```js
65
+ fs.createReadStream('/tmp/important.dat')
66
+ .pipe(through2({ objectMode: true, allowHalfOpen: false },
67
+ function (chunk, enc, cb) {
68
+ cb(null, 'wut?') // note we can use the second argument on the callback
69
+ // to provide data as an alternative to this.push('wut?')
70
+ }
71
+ )
72
+ .pipe(fs.createWriteStream('/tmp/wut.txt'))
73
+ ```
74
+
75
+ ### transformFunction
76
+
77
+ The `transformFunction` must have the following signature: `function (chunk, encoding, callback) {}`. A minimal implementation should call the `callback` function to indicate that the transformation is done, even if that transformation means discarding the chunk.
78
+
79
+ To queue a new chunk, call `this.push(chunk)`&mdash;this can be called as many times as required before the `callback()` if you have multiple pieces to send on.
80
+
81
+ Alternatively, you may use `callback(err, chunk)` as shorthand for emitting a single chunk or an error.
82
+
83
+ If you **do not provide a `transformFunction`** then you will get a simple pass-through stream.
84
+
85
+ ### flushFunction
86
+
87
+ 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.
88
+
89
+ ```js
90
+ fs.createReadStream('/tmp/important.dat')
91
+ .pipe(through2(
92
+ function (chunk, enc, cb) { cb(null, chunk) }, // transform is a noop
93
+ function (cb) { // flush function
94
+ this.push('tacking on an extra buffer to the end');
95
+ cb();
96
+ }
97
+ ))
98
+ .pipe(fs.createWriteStream('/tmp/wut.txt'));
99
+ ```
100
+
101
+ <b><code>through2.ctor([ options, ] transformFunction[, flushFunction ])</code></b>
102
+
103
+ 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.
104
+
105
+ ```js
106
+ var FToC = through2.ctor({objectMode: true}, function (record, encoding, callback) {
107
+ if (record.temp != null && record.unit = "F") {
108
+ record.temp = ( ( record.temp - 32 ) * 5 ) / 9
109
+ record.unit = "C"
110
+ }
111
+ this.push(record)
112
+ callback()
113
+ })
114
+
115
+ // Create instances of FToC like so:
116
+ var converter = new FToC()
117
+ // Or:
118
+ var converter = FToC()
119
+ // Or specify/override options when you instantiate, if you prefer:
120
+ var converter = FToC({objectMode: true})
121
+ ```
122
+
123
+ ## See Also
124
+
125
+ - [through2-map](https://github.com/brycebaril/through2-map) - Array.prototype.map analog for streams.
126
+ - [through2-filter](https://github.com/brycebaril/through2-filter) - Array.prototype.filter analog for streams.
127
+ - [through2-reduce](https://github.com/brycebaril/through2-reduce) - Array.prototype.reduce analog for streams.
128
+ - [through2-spy](https://github.com/brycebaril/through2-spy) - Wrapper for simple stream.PassThrough spies.
129
+
130
+ ## License
131
+
132
+ **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.
@@ -0,0 +1,15 @@
1
+ # readable-stream
2
+
3
+ ***Node-core streams for userland***
4
+
5
+ [![NPM](https://nodei.co/npm/readable-stream.png?downloads=true&downloadRank=true)](https://nodei.co/npm/readable-stream/)
6
+ [![NPM](https://nodei.co/npm-dl/readable-stream.png?&months=6&height=3)](https://nodei.co/npm/readable-stream/)
7
+
8
+ This package is a mirror of the Streams2 and Streams3 implementations in Node-core.
9
+
10
+ If you want to guarantee a stable streams base, regardless of what version of Node you, or the users of your libraries are using, use **readable-stream** *only* and avoid the *"stream"* module in Node-core.
11
+
12
+ **readable-stream** comes in two major versions, v1.0.x and v1.1.x. The former tracks the Streams2 implementation in Node 0.10, including bug-fixes and minor improvements as they are added. The latter tracks Streams3 as it develops in Node 0.11; we will likely see a v1.2.x branch for Node 0.12.
13
+
14
+ **readable-stream** uses proper patch-level versioning so if you pin to `"~1.0.0"` you’ll get the latest Node 0.10 Streams2 implementation, including any fixes and minor non-breaking improvements. The patch-level versions of 1.0.x and 1.1.x should mirror the patch-level versions of Node-core releases. You should prefer the **1.0.x** releases for now and when you’re ready to start using Streams3, pin to `"~1.1.0"`
15
+
@@ -0,0 +1 @@
1
+ module.exports = require("./lib/_stream_duplex.js")