Skip to content

Commit d6c391d

Browse files
committed
Updated from Node 8.1.3.
1 parent 98f4fb8 commit d6c391d

19 files changed

+1073
-1168
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# readable-stream
22

3-
***Node-core v8.1.2 streams for userland*** [![Build Status](https://travis-ci.org/nodejs/readable-stream.svg?branch=master)](https://travis-ci.org/nodejs/readable-stream)
3+
***Node-core v8.1.3 streams for userland*** [![Build Status](https://travis-ci.org/nodejs/readable-stream.svg?branch=master)](https://travis-ci.org/nodejs/readable-stream)
44

55

66
[![NPM](https://nodei.co/npm/readable-stream.png?downloads=true&downloadRank=true)](https://nodei.co/npm/readable-stream/)
@@ -18,7 +18,7 @@ npm install --save readable-stream
1818
This package is a mirror of the Streams2 and Streams3 implementations in
1919
Node-core.
2020

21-
Full documentation may be found on the [Node.js website](https://nodejs.org/dist/v8.1.2/docs/api/stream.html).
21+
Full documentation may be found on the [Node.js website](https://nodejs.org/dist/v8.1.3/docs/api/stream.html).
2222

2323
If you want to guarantee a stable streams base, regardless of what version of
2424
Node you, or the users of your libraries are using, use **readable-stream** *only* and avoid the *"stream"* module in Node-core, for background see [this blogpost](http://r.va.gg/2014/06/why-i-dont-use-nodes-core-stream-module.html).

lib/_stream_readable.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ function readableAddChunk(stream, chunk, encoding, addToFront, skipChunkCheck) {
254254
if (er) {
255255
stream.emit('error', er);
256256
} else if (state.objectMode || chunk && chunk.length > 0) {
257-
if (typeof chunk !== 'string' && Object.getPrototypeOf(chunk) !== Buffer.prototype && !state.objectMode) {
257+
if (typeof chunk !== 'string' && !state.objectMode && Object.getPrototypeOf(chunk) !== Buffer.prototype) {
258258
chunk = _uint8ArrayToBuffer(chunk);
259259
}
260260

lib/_stream_writable.js

+19-8
Original file line numberDiff line numberDiff line change
@@ -409,15 +409,26 @@ function doWrite(stream, state, writev, len, chunk, encoding, cb) {
409409

410410
function onwriteError(stream, state, sync, er, cb) {
411411
--state.pendingcb;
412-
if (sync) processNextTick(afterError, stream, state, cb, er);else afterError(stream, state, cb, er);
413412

414-
stream._writableState.errorEmitted = true;
415-
stream.emit('error', er);
416-
}
417-
418-
function afterError(stream, state, cb, err) {
419-
cb(err);
420-
finishMaybe(stream, state);
413+
if (sync) {
414+
// defer the callback if we are being called synchronously
415+
// to avoid piling up things on the stack
416+
processNextTick(cb, er);
417+
// this can emit finish, and it will always happen
418+
// after error
419+
processNextTick(finishMaybe, stream, state);
420+
stream._writableState.errorEmitted = true;
421+
stream.emit('error', er);
422+
} else {
423+
// the caller expect this to happen before if
424+
// it is async
425+
cb(er);
426+
stream._writableState.errorEmitted = true;
427+
stream.emit('error', er);
428+
// this can emit finish, but finish must
429+
// always follow error
430+
finishMaybe(stream, state);
431+
}
421432
}
422433

423434
function onwriteStateUpdate(state) {

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
"inherits": "~2.0.3",
99
"isarray": "~1.0.0",
1010
"process-nextick-args": "~1.0.6",
11-
"safe-buffer": "~5.1.0",
12-
"string_decoder": "~1.0.0",
11+
"safe-buffer": "~5.1.1",
12+
"string_decoder": "~1.0.3",
1313
"util-deprecate": "~1.0.1"
1414
},
1515
"devDependencies": {

test/common.js

+13-5
Original file line numberDiff line numberDiff line change
@@ -292,11 +292,11 @@ if (exports.isWindows) {
292292
}
293293

294294
var ifaces = os.networkInterfaces();
295+
var re = /lo/;
295296
exports.hasIPv6 = objectKeys(ifaces).some(function (name) {
296-
return (/lo/.test(name) && ifaces[name].some(function (info) {
297-
return info.family === 'IPv6';
298-
})
299-
);
297+
return re.test(name) && ifaces[name].some(function (info) {
298+
return info.family === 'IPv6';
299+
});
300300
});
301301

302302
/*
@@ -454,7 +454,7 @@ function leakedGlobals() {
454454
if (!knownGlobals.includes(global[val])) leaked.push(val);
455455
}if (global.__coverage__) {
456456
return leaked.filter(function (varname) {
457-
return !/^(cov_|__cov)/.test(varname);
457+
return !/^(?:cov_|__cov)/.test(varname);
458458
});
459459
} else {
460460
return leaked;
@@ -703,6 +703,14 @@ exports.expectWarning = function (nameOrMap, expected) {
703703
});
704704
} /*</replacement>*/
705705

706+
/*<replacement>*/if (!process.browser) {
707+
Object.defineProperty(exports, 'hasSmallICU', {
708+
get: function () {
709+
return process.binding('config').hasSmallICU;
710+
}
711+
});
712+
} /*</replacement>*/
713+
706714
// Useful for testing expected internal/error objects
707715
exports.expectsError = function expectsError(_ref) {
708716
var code = _ref.code,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*<replacement>*/
2+
var bufferShim = require('safe-buffer').Buffer;
3+
/*</replacement>*/
4+
var common = require('../common');
5+
var assert = require('assert/');
6+
7+
var _require = require('../../'),
8+
Readable = _require.Readable,
9+
Writable = _require.Writable,
10+
Transform = _require.Transform;
11+
12+
{
13+
var stream = new Readable({
14+
objectMode: true,
15+
read: common.mustCall(function () {
16+
stream.push(undefined);
17+
stream.push(null);
18+
})
19+
});
20+
21+
stream.on('data', common.mustCall(function (chunk) {
22+
assert.strictEqual(chunk, undefined);
23+
}));
24+
}
25+
26+
{
27+
var _stream = new Writable({
28+
objectMode: true,
29+
write: common.mustCall(function (chunk) {
30+
assert.strictEqual(chunk, undefined);
31+
})
32+
});
33+
34+
_stream.write(undefined);
35+
}
36+
37+
{
38+
var _stream2 = new Transform({
39+
objectMode: true,
40+
transform: common.mustCall(function (chunk) {
41+
_stream2.push(chunk);
42+
})
43+
});
44+
45+
_stream2.on('data', common.mustCall(function (chunk) {
46+
assert.strictEqual(chunk, undefined);
47+
}));
48+
49+
_stream2.write(undefined);
50+
}

test/parallel/test-stream-pipe-await-drain-push-while-write.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ var writable = new stream.Writable({
1919
if (chunk.length === 32 * 1024) {
2020
// first chunk
2121
var beforePush = readable._readableState.awaitDrain;
22-
readable.push(new Buffer(34 * 1024)); // above hwm
22+
readable.push(bufferShim.alloc(34 * 1024)); // above hwm
2323
// We should check if awaitDrain counter is increased.
2424
var afterPush = readable._readableState.awaitDrain;
2525
assert.strictEqual(afterPush - beforePush, 1, 'Counter is not increased for awaitDrain');
@@ -31,7 +31,7 @@ var writable = new stream.Writable({
3131
});
3232

3333
// A readable stream which produces two buffers.
34-
var bufs = [new Buffer(32 * 1024), new Buffer(33 * 1024)]; // above hwm
34+
var bufs = [bufferShim.alloc(32 * 1024), bufferShim.alloc(33 * 1024)]; // above hwm
3535
var readable = new stream.Readable({
3636
read: function () {
3737
while (bufs.length > 0) {

test/parallel/test-stream-readable-invalid-chunk.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ var readable = new stream.Readable({
1010
read: common.noop
1111
});
1212

13+
var errMessage = /Invalid non-string\/buffer chunk/;
1314
assert.throws(function () {
1415
return readable.push([]);
15-
}, /Invalid non-string\/buffer chunk/);
16+
}, errMessage);
1617
assert.throws(function () {
1718
return readable.push({});
18-
}, /Invalid non-string\/buffer chunk/);
19+
}, errMessage);
1920
assert.throws(function () {
2021
return readable.push(0);
21-
}, /Invalid non-string\/buffer chunk/);
22+
}, errMessage);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
/*<replacement>*/
2+
var bufferShim = require('safe-buffer').Buffer;
3+
/*</replacement>*/
4+
5+
var common = require('../common');
6+
var assert = require('assert/');
7+
var stream = require('../../');
8+
9+
// ensure consistency between the finish event when using cork()
10+
// and writev and when not using them
11+
12+
{
13+
var writable = new stream.Writable();
14+
15+
writable._write = function (chunks, encoding, cb) {
16+
cb(new Error('write test error'));
17+
};
18+
19+
var firstError = false;
20+
writable.on('finish', common.mustCall(function () {
21+
assert.strictEqual(firstError, true);
22+
}));
23+
24+
writable.on('prefinish', common.mustCall());
25+
26+
writable.on('error', common.mustCall(function (er) {
27+
assert.strictEqual(er.message, 'write test error');
28+
firstError = true;
29+
}));
30+
31+
writable.end('test');
32+
}
33+
34+
{
35+
var _writable = new stream.Writable();
36+
37+
_writable._write = function (chunks, encoding, cb) {
38+
setImmediate(cb, new Error('write test error'));
39+
};
40+
41+
var _firstError = false;
42+
_writable.on('finish', common.mustCall(function () {
43+
assert.strictEqual(_firstError, true);
44+
}));
45+
46+
_writable.on('prefinish', common.mustCall());
47+
48+
_writable.on('error', common.mustCall(function (er) {
49+
assert.strictEqual(er.message, 'write test error');
50+
_firstError = true;
51+
}));
52+
53+
_writable.end('test');
54+
}
55+
56+
{
57+
var _writable2 = new stream.Writable();
58+
59+
_writable2._write = function (chunks, encoding, cb) {
60+
cb(new Error('write test error'));
61+
};
62+
63+
_writable2._writev = function (chunks, cb) {
64+
cb(new Error('writev test error'));
65+
};
66+
67+
var _firstError2 = false;
68+
_writable2.on('finish', common.mustCall(function () {
69+
assert.strictEqual(_firstError2, true);
70+
}));
71+
72+
_writable2.on('prefinish', common.mustCall());
73+
74+
_writable2.on('error', common.mustCall(function (er) {
75+
assert.strictEqual(er.message, 'writev test error');
76+
_firstError2 = true;
77+
}));
78+
79+
_writable2.cork();
80+
_writable2.write('test');
81+
82+
setImmediate(function () {
83+
_writable2.end('test');
84+
});
85+
}
86+
87+
{
88+
var _writable3 = new stream.Writable();
89+
90+
_writable3._write = function (chunks, encoding, cb) {
91+
setImmediate(cb, new Error('write test error'));
92+
};
93+
94+
_writable3._writev = function (chunks, cb) {
95+
setImmediate(cb, new Error('writev test error'));
96+
};
97+
98+
var _firstError3 = false;
99+
_writable3.on('finish', common.mustCall(function () {
100+
assert.strictEqual(_firstError3, true);
101+
}));
102+
103+
_writable3.on('prefinish', common.mustCall());
104+
105+
_writable3.on('error', common.mustCall(function (er) {
106+
assert.strictEqual(er.message, 'writev test error');
107+
_firstError3 = true;
108+
}));
109+
110+
_writable3.cork();
111+
_writable3.write('test');
112+
113+
setImmediate(function () {
114+
_writable3.end('test');
115+
});
116+
}
117+
118+
// Regression test for
119+
// https://github.com/nodejs/node/issues/13812
120+
121+
{
122+
var rs = new stream.Readable();
123+
rs.push('ok');
124+
rs.push(null);
125+
rs._read = function () {};
126+
127+
var ws = new stream.Writable();
128+
var _firstError4 = false;
129+
130+
ws.on('finish', common.mustCall(function () {
131+
assert.strictEqual(_firstError4, true);
132+
}));
133+
ws.on('error', common.mustCall(function () {
134+
_firstError4 = true;
135+
}));
136+
137+
ws._write = function (chunk, encoding, done) {
138+
setImmediate(done, new Error());
139+
};
140+
rs.pipe(ws);
141+
}
142+
143+
{
144+
var _rs = new stream.Readable();
145+
_rs.push('ok');
146+
_rs.push(null);
147+
_rs._read = function () {};
148+
149+
var _ws = new stream.Writable();
150+
151+
_ws.on('finish', common.mustNotCall());
152+
_ws.on('error', common.mustCall());
153+
154+
_ws._write = function (chunk, encoding, done) {
155+
done(new Error());
156+
};
157+
_rs.pipe(_ws);
158+
}

0 commit comments

Comments
 (0)