Skip to content

Commit 757e685

Browse files
addaleaxMylesBorins
authored andcommittedJan 9, 2018
stream: remove undefined check
`validChunk` allowed `undefined` as a chunk in object mode; however, this was redundant, since: - `validChunk()` is only used by `.write()` - If the `validChunk()` check passes for `undefined`, `.write()` calls `writeOrBuffer()` - If `writeOrBuffer()` does not receive a Buffer, it calls `decodeChunk()` - `decodeChunk()` ignores `undefined` because it checks `typeof chunk === 'string'` - After that call, `chunk.length` is accessed, which throws an error if `chunk` is undefined`. This “fixes” a bug in the sense that `state.pendingcb` is no longer incremented for write attempts that fail like this. PR-URL: #17644 Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Jon Moss <[email protected]>
1 parent 6d9b1e4 commit 757e685

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed
 

‎lib/_stream_writable.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,7 @@ function validChunk(stream, state, chunk, cb) {
249249

250250
if (chunk === null) {
251251
er = new errors.TypeError('ERR_STREAM_NULL_VALUES');
252-
} else if (typeof chunk !== 'string' &&
253-
chunk !== undefined &&
254-
!state.objectMode) {
252+
} else if (typeof chunk !== 'string' && !state.objectMode) {
255253
er = new errors.TypeError('ERR_INVALID_ARG_TYPE', 'chunk',
256254
['string', 'Buffer']);
257255
}

0 commit comments

Comments
 (0)
Please sign in to comment.