@@ -47,10 +47,10 @@ There are four fundamental stream types within Node.js:
47
47
### Object Mode
48
48
49
49
All 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".
54
54
55
55
Stream instances are switched into object mode using the ` objectMode ` option
56
56
when the stream is created. Attempting to switch an existing stream into
@@ -352,12 +352,17 @@ See also: [`writable.uncork()`][].
352
352
##### writable.end([ chunk] [ , encoding ] [ , callback] )
353
353
<!-- YAML
354
354
added: 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.
355
359
-->
356
360
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
361
366
* ` callback ` {Function} Optional callback for when the stream is finished
362
367
363
368
Calling the ` writable.end() ` method signals that no more data will be written
@@ -434,14 +439,20 @@ See also: [`writable.cork()`][].
434
439
<!-- YAML
435
440
added: v0.9.4
436
441
changes:
442
+ - version: REPLACEME
443
+ pr-url: https://github.com/nodejs/node/pull/11608
444
+ description: The `chunk` argument can now be a `Uint8Array` instance.
437
445
- version: v6.0.0
438
446
pr-url: https://github.com/nodejs/node/pull/6170
439
447
description: Passing `null` as the `chunk` parameter will always be
440
448
considered invalid now, even in object mode.
441
449
-->
442
450
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
445
456
* ` callback ` {Function} Callback for when this chunk of data is flushed
446
457
* Returns: {boolean} ` false ` if the stream wishes for the calling code to
447
458
wait for the ` 'drain' ` event to be emitted before continuing to write
@@ -985,9 +996,16 @@ setTimeout(() => {
985
996
##### readable.unshift(chunk)
986
997
<!-- YAML
987
998
added: 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.
988
1003
-->
989
1004
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 ` .
991
1009
992
1010
The ` readable.unshift() ` method pushes a chunk of data back into the internal
993
1011
buffer. 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
1274
1292
Defaults to ` true `
1275
1293
* ` objectMode ` {boolean} Whether or not the
1276
1294
[ ` 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 `
1279
1298
* ` write ` {Function} Implementation for the
1280
1299
[ ` stream._write() ` ] [ stream-_write ] method.
1281
1300
* ` writev ` {Function} Implementation for the
@@ -1564,16 +1583,26 @@ internal to the class that defines it, and should never be called directly by
1564
1583
user programs.
1565
1584
1566
1585
#### 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
+ -->
1567
1592
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
1570
1598
Buffer encoding, such as ` 'utf8' ` or ` 'ascii' `
1571
1599
* Returns {boolean} ` true ` if additional chunks of data may continued to be
1572
1600
pushed; ` false ` otherwise.
1573
1601
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.
1577
1606
1578
1607
When the Readable is operating in paused mode, the data added with
1579
1608
` readable.push() ` can be read out by calling the
@@ -2088,8 +2117,8 @@ Readable stream class internals.
2088
2117
2089
2118
Use of ` readable.push('') ` is not recommended.
2090
2119
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
2093
2122
[ ` readable.push() ` ] [ stream-push ] , the call will end the reading process.
2094
2123
However, because the argument is an empty string, no data is added to the
2095
2124
readable buffer so there is nothing for a user to consume.
0 commit comments