Skip to content

Commit 07604f3

Browse files
committed
Merge pull request #98 from chrisdickinson/backport
backport iojs v1.0.0 streams changes
2 parents b1036fb + 2bb6a6a commit 07604f3

File tree

70 files changed

+864
-2284
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+864
-2284
lines changed

build/build.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ const hyperquest = require('hyperzip')(require('hyperdirect'))
99
, files = require('./files')
1010
, testReplace = require('./test-replacements')
1111

12-
, srcurlpfx = 'https://raw.githubusercontent.com/joyent/node/v' + process.argv[2] + '-release/'
12+
, srcurlpfx = 'https://raw.githubusercontent.com/iojs/io.js/v' + process.argv[2] + '-release/'
1313
, libsrcurl = srcurlpfx + 'lib/'
14-
, testsrcurl = srcurlpfx + 'test/simple/'
15-
, testlisturl = 'https://github.com/joyent/node/tree/v' + process.argv[2] + '-release/test/simple'
14+
, testsrcurl = srcurlpfx + 'test/parallel/'
15+
, testlisturl = 'https://github.com/iojs/io.js/tree/v' + process.argv[2] + '-release/test/parallel'
1616
, libourroot = path.join(__dirname, '../lib/')
17-
, testourroot = path.join(__dirname, '../test/simple/')
17+
, testourroot = path.join(__dirname, '../test/parallel/')
1818

1919

20-
if (!/^0\.1\d+\.\d+$/.test(process.argv[2])) {
20+
if (!/\d\.\d\.\d+/.test(process.argv[2])) {
2121
console.error('Usage: build.js xx.yy.zz')
2222
return process.exit(1);
2323
}
@@ -62,7 +62,7 @@ function processTestFile (file) {
6262
}
6363

6464

65-
if (!/0\.1\d\.\d+/.test(process.argv[2])) {
65+
if (!/\d\.\d\.\d+/.test(process.argv[2])) {
6666
console.log('Usage: build.js <node version>')
6767
return process.exit(-1)
6868
}
@@ -93,7 +93,7 @@ hyperquest(testlisturl).pipe(bl(function (err, data) {
9393
// Grab the joyent/node test/common.js
9494

9595
processFile(
96-
testsrcurl.replace(/simple\/$/, 'common.js')
96+
testsrcurl.replace(/parallel\/$/, 'common.js')
9797
, path.join(testourroot, '../common.js')
9898
, testReplace['common.js']
9999
)

build/files.js

+14
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,17 @@ const headRegexp = /(^module.exports = \w+;?)/m
5757
+ '}\n/*</replacement>*/\n'
5858
]
5959

60+
, deprecateReplacement = [
61+
/util.deprecate/
62+
, 'require(\'util-deprecate\')'
63+
]
64+
65+
, objectDefinePropertyReplacement = [
66+
/Object.defineProperties/
67+
, 'if (Object.defineProperties) $1'
68+
]
69+
70+
6071
, isArrayDefine = [
6172
headRegexp
6273
, '$1\n\n/*<replacement>*/\nvar isArray = require(\'isarray\');\n/*</replacement>*/\n'
@@ -142,5 +153,8 @@ module.exports['_stream_writable.js'] = [
142153
, bufferReplacement
143154
, utilReplacement
144155
, stringDecoderReplacement
156+
, debugLogReplacement
157+
, deprecateReplacement
158+
, objectDefinePropertyReplacement
145159
, [ /^var assert = require\('assert'\);$/m, '' ]
146160
]

lib/_stream_duplex.js

+6-23
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,10 @@
1-
// Copyright Joyent, Inc. and other Node contributors.
2-
//
3-
// Permission is hereby granted, free of charge, to any person obtaining a
4-
// copy of this software and associated documentation files (the
5-
// "Software"), to deal in the Software without restriction, including
6-
// without limitation the rights to use, copy, modify, merge, publish,
7-
// distribute, sublicense, and/or sell copies of the Software, and to permit
8-
// persons to whom the Software is furnished to do so, subject to the
9-
// following conditions:
10-
//
11-
// The above copyright notice and this permission notice shall be included
12-
// in all copies or substantial portions of the Software.
13-
//
14-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15-
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16-
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17-
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18-
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19-
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20-
// USE OR OTHER DEALINGS IN THE SOFTWARE.
21-
221
// a duplex stream is just a stream that is both readable and writable.
232
// Since JS doesn't have multiple prototypal inheritance, this class
243
// prototypally inherits from Readable, and then parasitically from
254
// Writable.
265

6+
'use strict';
7+
278
module.exports = Duplex;
289

2910
/*<replacement>*/
@@ -45,10 +26,12 @@ var Writable = require('./_stream_writable');
4526

4627
util.inherits(Duplex, Readable);
4728

48-
forEach(objectKeys(Writable.prototype), function(method) {
29+
var keys = objectKeys(Writable.prototype);
30+
for (var v = 0; v < keys.length; v++) {
31+
var method = keys[v];
4932
if (!Duplex.prototype[method])
5033
Duplex.prototype[method] = Writable.prototype[method];
51-
});
34+
}
5235

5336
function Duplex(options) {
5437
if (!(this instanceof Duplex))

lib/_stream_passthrough.js

+2-21
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,9 @@
1-
// Copyright Joyent, Inc. and other Node contributors.
2-
//
3-
// Permission is hereby granted, free of charge, to any person obtaining a
4-
// copy of this software and associated documentation files (the
5-
// "Software"), to deal in the Software without restriction, including
6-
// without limitation the rights to use, copy, modify, merge, publish,
7-
// distribute, sublicense, and/or sell copies of the Software, and to permit
8-
// persons to whom the Software is furnished to do so, subject to the
9-
// following conditions:
10-
//
11-
// The above copyright notice and this permission notice shall be included
12-
// in all copies or substantial portions of the Software.
13-
//
14-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15-
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16-
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17-
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18-
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19-
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20-
// USE OR OTHER DEALINGS IN THE SOFTWARE.
21-
221
// a passthrough stream.
232
// basically just the most minimal sort of Transform stream.
243
// Every written chunk gets output as-is.
254

5+
'use strict';
6+
267
module.exports = PassThrough;
278

289
var Transform = require('./_stream_transform');

lib/_stream_readable.js

+26-36
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,4 @@
1-
// Copyright Joyent, Inc. and other Node contributors.
2-
//
3-
// Permission is hereby granted, free of charge, to any person obtaining a
4-
// copy of this software and associated documentation files (the
5-
// "Software"), to deal in the Software without restriction, including
6-
// without limitation the rights to use, copy, modify, merge, publish,
7-
// distribute, sublicense, and/or sell copies of the Software, and to permit
8-
// persons to whom the Software is furnished to do so, subject to the
9-
// following conditions:
10-
//
11-
// The above copyright notice and this permission notice shall be included
12-
// in all copies or substantial portions of the Software.
13-
//
14-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15-
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16-
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17-
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18-
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19-
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20-
// USE OR OTHER DEALINGS IN THE SOFTWARE.
1+
'use strict';
212

223
module.exports = Readable;
234

@@ -67,10 +48,17 @@ function ReadableState(options, stream) {
6748

6849
options = options || {};
6950

51+
// object stream flag. Used to make read(n) ignore n and to
52+
// make all the buffer merging and length checks go away
53+
this.objectMode = !!options.objectMode;
54+
55+
if (stream instanceof Duplex)
56+
this.objectMode = this.objectMode || !!options.readableObjectMode;
57+
7058
// the point at which it stops calling _read() to fill the buffer
7159
// Note: 0 is a valid value, means "don't call _read preemptively ever"
7260
var hwm = options.highWaterMark;
73-
var defaultHwm = options.objectMode ? 16 : 16 * 1024;
61+
var defaultHwm = this.objectMode ? 16 : 16 * 1024;
7462
this.highWaterMark = (hwm || hwm === 0) ? hwm : defaultHwm;
7563

7664
// cast to ints.
@@ -97,14 +85,6 @@ function ReadableState(options, stream) {
9785
this.emittedReadable = false;
9886
this.readableListening = false;
9987

100-
101-
// object stream flag. Used to make read(n) ignore n and to
102-
// make all the buffer merging and length checks go away
103-
this.objectMode = !!options.objectMode;
104-
105-
if (stream instanceof Duplex)
106-
this.objectMode = this.objectMode || !!options.readableObjectMode;
107-
10888
// Crypto is kind of old and crusty. Historically, its default string
10989
// encoding is 'binary' so we have to make this configurable.
11090
// Everything else in the universe uses 'utf8', though.
@@ -168,11 +148,15 @@ Readable.prototype.unshift = function(chunk) {
168148
return readableAddChunk(this, state, chunk, '', true);
169149
};
170150

151+
Readable.prototype.isPaused = function() {
152+
return this._readableState.flowing === false;
153+
};
154+
171155
function readableAddChunk(stream, state, chunk, encoding, addToFront) {
172156
var er = chunkInvalid(state, chunk);
173157
if (er) {
174158
stream.emit('error', er);
175-
} else if (util.isNullOrUndefined(chunk)) {
159+
} else if (chunk === null) {
176160
state.reading = false;
177161
if (!state.ended)
178162
onEofChunk(stream, state);
@@ -261,7 +245,7 @@ function howMuchToRead(n, state) {
261245
if (state.objectMode)
262246
return n === 0 ? 0 : 1;
263247

264-
if (isNaN(n) || util.isNull(n)) {
248+
if (util.isNull(n) || isNaN(n)) {
265249
// only flow one buffer at a time
266250
if (state.flowing && state.buffer.length)
267251
return state.buffer[0].length;
@@ -737,10 +721,6 @@ Readable.prototype.resume = function() {
737721
if (!state.flowing) {
738722
debug('resume');
739723
state.flowing = true;
740-
if (!state.reading) {
741-
debug('resume read 0');
742-
this.read(0);
743-
}
744724
resume(this, state);
745725
}
746726
return this;
@@ -756,6 +736,11 @@ function resume(stream, state) {
756736
}
757737

758738
function resume_(stream, state) {
739+
if (!state.reading) {
740+
debug('resume read 0');
741+
stream.read(0);
742+
}
743+
759744
state.resumeScheduled = false;
760745
stream.emit('resume');
761746
flow(stream);
@@ -806,7 +791,12 @@ Readable.prototype.wrap = function(stream) {
806791
debug('wrapped data');
807792
if (state.decoder)
808793
chunk = state.decoder.write(chunk);
809-
if (!chunk || !state.objectMode && !chunk.length)
794+
795+
// don't skip over falsy values in objectMode
796+
//if (state.objectMode && util.isNullOrUndefined(chunk))
797+
if (state.objectMode && (chunk === null || chunk === undefined))
798+
return;
799+
else if (!state.objectMode && (!chunk || !chunk.length))
810800
return;
811801

812802
var ret = self.push(chunk);

lib/_stream_transform.js

+4-24
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,3 @@
1-
// Copyright Joyent, Inc. and other Node contributors.
2-
//
3-
// Permission is hereby granted, free of charge, to any person obtaining a
4-
// copy of this software and associated documentation files (the
5-
// "Software"), to deal in the Software without restriction, including
6-
// without limitation the rights to use, copy, modify, merge, publish,
7-
// distribute, sublicense, and/or sell copies of the Software, and to permit
8-
// persons to whom the Software is furnished to do so, subject to the
9-
// following conditions:
10-
//
11-
// The above copyright notice and this permission notice shall be included
12-
// in all copies or substantial portions of the Software.
13-
//
14-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15-
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16-
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17-
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18-
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19-
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20-
// USE OR OTHER DEALINGS IN THE SOFTWARE.
21-
22-
231
// a transform stream is a readable/writable stream where you do
242
// something with the data. Sometimes it's called a "filter",
253
// but that's not a great name for it, since that implies a thing where
@@ -62,6 +40,8 @@
6240
// would be consumed, and then the rest would wait (un-transformed) until
6341
// the results of the previous transformed chunk were consumed.
6442

43+
'use strict';
44+
6545
module.exports = Transform;
6646

6747
var Duplex = require('./_stream_duplex');
@@ -74,7 +54,7 @@ util.inherits = require('inherits');
7454
util.inherits(Transform, Duplex);
7555

7656

77-
function TransformState(options, stream) {
57+
function TransformState(stream) {
7858
this.afterTransform = function(er, data) {
7959
return afterTransform(stream, er, data);
8060
};
@@ -117,7 +97,7 @@ function Transform(options) {
11797

11898
Duplex.call(this, options);
11999

120-
this._transformState = new TransformState(options, this);
100+
this._transformState = new TransformState(this);
121101

122102
// when the writable side finishes, then flush out anything remaining.
123103
var stream = this;

0 commit comments

Comments
 (0)