@@ -47,10 +47,10 @@ There are four fundamental stream types within Node.js:
4747### Object Mode
4848
4949All streams created by Node.js APIs operate exclusively on strings and ` Buffer `
50- objects. It is possible, however, for stream implementations to work with other
51- types of JavaScript values (with the exception of ` null ` , which serves a special
52- purpose within streams). Such streams are considered to operate in "object
53- mode".
50+ (or ` Uint8Array ` ) objects. It is possible, however, for stream implementations
51+ to work with other types of JavaScript values (with the exception of ` null ` ,
52+ which serves a special purpose within streams). Such streams are considered to
53+ operate in "object mode".
5454
5555Stream instances are switched into object mode using the ` objectMode ` option
5656when the stream is created. Attempting to switch an existing stream into
@@ -352,12 +352,17 @@ See also: [`writable.uncork()`][].
352352##### writable.end([ chunk] [ , encoding ] [ , callback] )
353353<!-- YAML
354354added: v0.9.4
355+ changes:
356+ - version: REPLACEME
357+ pr-url: https://github.com/nodejs/node/pull/11608
358+ description: The `chunk` argument can now be a `Uint8Array` instance.
355359-->
356360
357- * ` chunk ` {string|Buffer|any} Optional data to write. For streams not operating
358- in object mode, ` chunk ` must be a string or a ` Buffer ` . For object mode
359- streams, ` chunk ` may be any JavaScript value other than ` null ` .
360- * ` encoding ` {string} The encoding, if ` chunk ` is a String
361+ * ` chunk ` {string|Buffer|Uint8Array|any} Optional data to write. For streams
362+ not operating in object mode, ` chunk ` must be a string, ` Buffer ` or
363+ ` Uint8Array ` . For object mode streams, ` chunk ` may be any JavaScript value
364+ other than ` null ` .
365+ * ` encoding ` {string} The encoding, if ` chunk ` is a string
361366* ` callback ` {Function} Optional callback for when the stream is finished
362367
363368Calling the ` writable.end() ` method signals that no more data will be written
@@ -434,14 +439,20 @@ See also: [`writable.cork()`][].
434439<!-- YAML
435440added: v0.9.4
436441changes:
442+ - version: REPLACEME
443+ pr-url: https://github.com/nodejs/node/pull/11608
444+ description: The `chunk` argument can now be a `Uint8Array` instance.
437445 - version: v6.0.0
438446 pr-url: https://github.com/nodejs/node/pull/6170
439447 description: Passing `null` as the `chunk` parameter will always be
440448 considered invalid now, even in object mode.
441449-->
442450
443- * ` chunk ` {string|Buffer} The data to write
444- * ` encoding ` {string} The encoding, if ` chunk ` is a String
451+ * ` chunk ` {string|Buffer|Uint8Array|any} Optional data to write. For streams
452+ not operating in object mode, ` chunk ` must be a string, ` Buffer ` or
453+ ` Uint8Array ` . For object mode streams, ` chunk ` may be any JavaScript value
454+ other than ` null ` .
455+ * ` encoding ` {string} The encoding, if ` chunk ` is a string
445456* ` callback ` {Function} Callback for when this chunk of data is flushed
446457* Returns: {boolean} ` false ` if the stream wishes for the calling code to
447458 wait for the ` 'drain' ` event to be emitted before continuing to write
@@ -985,9 +996,16 @@ setTimeout(() => {
985996##### readable.unshift(chunk)
986997<!-- YAML
987998added: v0.9.11
999+ changes:
1000+ - version: REPLACEME
1001+ pr-url: https://github.com/nodejs/node/pull/11608
1002+ description: The `chunk` argument can now be a `Uint8Array` instance.
9881003-->
9891004
990- * ` chunk ` {Buffer|string|any} Chunk of data to unshift onto the read queue
1005+ * ` chunk ` {Buffer|Uint8Array|string|any} Chunk of data to unshift onto the
1006+ read queue. For streams not operating in object mode, ` chunk ` must be a
1007+ string, ` Buffer ` or ` Uint8Array ` . For object mode streams, ` chunk ` may be
1008+ any JavaScript value other than ` null ` .
9911009
9921010The ` readable.unshift() ` method pushes a chunk of data back into the internal
9931011buffer. This is useful in certain situations where a stream is being consumed by
@@ -1274,8 +1292,9 @@ constructor and implement the `writable._write()` method. The
12741292 Defaults to ` true `
12751293 * ` objectMode ` {boolean} Whether or not the
12761294 [ ` stream.write(anyObj) ` ] [ stream-write ] is a valid operation. When set,
1277- it becomes possible to write JavaScript values other than string or
1278- ` Buffer ` if supported by the stream implementation. Defaults to ` false `
1295+ it becomes possible to write JavaScript values other than string,
1296+ ` Buffer ` or ` Uint8Array ` if supported by the stream implementation.
1297+ Defaults to ` false `
12791298 * ` write ` {Function} Implementation for the
12801299 [ ` stream._write() ` ] [ stream-_write ] method.
12811300 * ` writev ` {Function} Implementation for the
@@ -1564,16 +1583,26 @@ internal to the class that defines it, and should never be called directly by
15641583user programs.
15651584
15661585#### readable.push(chunk[ , encoding] )
1586+ <!-- YAML
1587+ changes:
1588+ - version: REPLACEME
1589+ pr-url: https://github.com/nodejs/node/pull/11608
1590+ description: The `chunk` argument can now be a `Uint8Array` instance.
1591+ -->
15671592
1568- * ` chunk ` {Buffer|null|string|any} Chunk of data to push into the read queue
1569- * ` encoding ` {string} Encoding of String chunks. Must be a valid
1593+ * ` chunk ` {Buffer|Uint8Array|string|null|any} Chunk of data to push into the
1594+ read queue. For streams not operating in object mode, ` chunk ` must be a
1595+ string, ` Buffer ` or ` Uint8Array ` . For object mode streams, ` chunk ` may be
1596+ any JavaScript value.
1597+ * ` encoding ` {string} Encoding of string chunks. Must be a valid
15701598 Buffer encoding, such as ` 'utf8' ` or ` 'ascii' `
15711599* Returns {boolean} ` true ` if additional chunks of data may continued to be
15721600 pushed; ` false ` otherwise.
15731601
1574- When ` chunk ` is not ` null ` , the ` chunk ` of data will be added to the
1575- internal queue for users of the stream to consume. Passing ` chunk ` as ` null `
1576- signals the end of the stream (EOF), after which no more data can be written.
1602+ When ` chunk ` is a ` Buffer ` , ` Uint8Array ` or ` string ` , the ` chunk ` of data will
1603+ be added to the internal queue for users of the stream to consume.
1604+ Passing ` chunk ` as ` null ` signals the end of the stream (EOF), after which no
1605+ more data can be written.
15771606
15781607When the Readable is operating in paused mode, the data added with
15791608` readable.push() ` can be read out by calling the
@@ -2088,8 +2117,8 @@ Readable stream class internals.
20882117
20892118Use of ` readable.push('') ` is not recommended.
20902119
2091- Pushing a zero-byte string or ` Buffer ` to a stream that is not in object mode
2092- has an interesting side effect. Because it * is* a call to
2120+ Pushing a zero-byte string, ` Buffer ` or ` Uint8Array ` to a stream that is not in
2121+ object mode has an interesting side effect. Because it * is* a call to
20932122[ ` readable.push() ` ] [ stream-push ] , the call will end the reading process.
20942123However, because the argument is an empty string, no data is added to the
20952124readable buffer so there is nothing for a user to consume.
0 commit comments