Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9847f84

Browse filesBrowse files
Italo A. Casasevanlucas
authored andcommitted
doc: add added: information for stream
Ref: #6578 PR-URL: #7287 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Claudio Rodriguez <cjrodr@yahoo.com>
1 parent 39f5d9c commit 9847f84
Copy full SHA for 9847f84

File tree

Expand file treeCollapse file tree

1 file changed

+90
-3
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+90
-3
lines changed
Open diff view settings
Collapse file

‎doc/api/stream.md‎

Copy file name to clipboardExpand all lines: doc/api/stream.md
+90-3Lines changed: 90 additions & 3 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ const server = http.createServer( (req, res) => {
116116
// req is an http.IncomingMessage, which is a Readable Stream
117117
// res is an http.ServerResponse, which is a Writable Stream
118118

119-
var body = '';
119+
let body = '';
120120
// Get the data as utf8 strings.
121121
// If an encoding is not set, Buffer objects will be received.
122122
req.setEncoding('utf8');
@@ -205,10 +205,16 @@ myStream.end('done writing data');
205205
```
206206

207207
#### Class: stream.Writable
208+
<!-- YAML
209+
added: v0.9.4
210+
-->
208211

209212
<!--type=class-->
210213

211214
##### Event: 'close'
215+
<!-- YAML
216+
added: v0.9.4
217+
-->
212218

213219
The `'close'` event is emitted when the stream and any of its underlying
214220
resources (a file descriptor, for example) have been closed. The event indicates
@@ -217,6 +223,9 @@ that no more events will be emitted, and no further computation will occur.
217223
Not all Writable streams will emit the `'close'` event.
218224

219225
##### Event: 'drain'
226+
<!-- YAML
227+
added: v0.9.4
228+
-->
220229

221230
If a call to [`stream.write(chunk)`][stream-write] returns `false`, the
222231
`'drain'` event will be emitted when it is appropriate to resume writing data
@@ -226,7 +235,7 @@ to the stream.
226235
// Write the data to the supplied writable stream one million times.
227236
// Be attentive to back-pressure.
228237
function writeOneMillionTimes(writer, data, encoding, callback) {
229-
var i = 1000000;
238+
let i = 1000000;
230239
write();
231240
function write() {
232241
var ok = true;
@@ -251,6 +260,9 @@ function writeOneMillionTimes(writer, data, encoding, callback) {
251260
```
252261

253262
##### Event: 'error'
263+
<!-- YAML
264+
added: v0.9.4
265+
-->
254266

255267
* {Error}
256268

@@ -260,6 +272,9 @@ data. The listener callback is passed a single `Error` argument when called.
260272
*Note*: The stream is not closed when the `'error'` event is emitted.
261273

262274
##### Event: 'finish'
275+
<!-- YAML
276+
added: v0.9.4
277+
-->
263278

264279
The `'finish'` event is emitted after the [`stream.end()`][stream-end] method
265280
has been called, and all data has been flushed to the underlying system.
@@ -276,6 +291,9 @@ writer.on('finish', () => {
276291
```
277292

278293
##### Event: 'pipe'
294+
<!-- YAML
295+
added: v0.9.4
296+
-->
279297

280298
* `src` {stream.Readable} source stream that is piping to this writable
281299

@@ -293,6 +311,9 @@ reader.pipe(writer);
293311
```
294312

295313
##### Event: 'unpipe'
314+
<!-- YAML
315+
added: v0.9.4
316+
-->
296317

297318
* `src` {[Readable][] Stream} The source stream that
298319
[unpiped][`stream.unpipe()`] this writable
@@ -313,6 +334,9 @@ reader.unpipe(writer);
313334
```
314335

315336
##### writable.cork()
337+
<!-- YAML
338+
added: v0.11.2
339+
-->
316340

317341
The `writable.cork()` method forces all written data to be buffered in memory.
318342
The buffered data will be flushed when either the [`stream.uncork()`][] or
@@ -325,6 +349,9 @@ implementations that implement the `writable._writev()` method can perform
325349
buffered writes in a more optimized manner.
326350

327351
##### writable.end([chunk][, encoding][, callback])
352+
<!-- YAML
353+
added: v0.9.4
354+
-->
328355

329356
* `chunk` {String|Buffer|any} Optional data to write. For streams not operating
330357
in object mode, `chunk` must be a string or a `Buffer`. For object mode
@@ -350,6 +377,9 @@ file.end('world!');
350377
```
351378

352379
##### writable.setDefaultEncoding(encoding)
380+
<!-- YAML
381+
added: v0.11.15
382+
-->
353383

354384
* `encoding` {String} The new default encoding
355385
* Return: `this`
@@ -358,6 +388,9 @@ The `writable.setDefaultEncoding()` method sets the default `encoding` for a
358388
[Writable][] stream.
359389

360390
##### writable.uncork()
391+
<!-- YAML
392+
added: v0.11.2
393+
-->
361394

362395
The `writable.uncork()` method flushes all data buffered since
363396
[`stream.cork()`][] was called.
@@ -391,6 +424,9 @@ process.nextTick(() => {
391424
```
392425

393426
##### writable.write(chunk[, encoding][, callback])
427+
<!-- YAML
428+
added: v0.9.4
429+
-->
394430

395431
* `chunk` {String|Buffer} The data to write
396432
* `encoding` {String} The encoding, if `chunk` is a String
@@ -516,10 +552,16 @@ require more fine-grained control over the transfer and generation of data can
516552
use the [`EventEmitter`][] and `readable.pause()`/`readable.resume()` APIs.
517553

518554
#### Class: stream.Readable
555+
<!-- YAML
556+
added: v0.9.4
557+
-->
519558

520559
<!--type=class-->
521560

522561
##### Event: 'close'
562+
<!-- YAML
563+
added: v0.9.4
564+
-->
523565

524566
The `'close'` event is emitted when the stream and any of its underlying
525567
resources (a file descriptor, for example) have been closed. The event indicates
@@ -528,6 +570,9 @@ that no more events will be emitted, and no further computation will occur.
528570
Not all [Readable][] streams will emit the `'close'` event.
529571

530572
##### Event: 'data'
573+
<!-- YAML
574+
added: v0.9.4
575+
-->
531576

532577
* `chunk` {Buffer|String|any} The chunk of data. For streams that are not
533578
operating in object mode, the chunk will be either a string or `Buffer`.
@@ -558,6 +603,9 @@ readable.on('data', (chunk) => {
558603
```
559604

560605
##### Event: 'end'
606+
<!-- YAML
607+
added: v0.9.4
608+
-->
561609

562610
The `'end'` event is emitted when there is no more data to be consumed from
563611
the stream.
@@ -578,6 +626,9 @@ readable.on('end', () => {
578626
```
579627

580628
##### Event: 'error'
629+
<!-- YAML
630+
added: v0.9.4
631+
-->
581632

582633
* {Error}
583634

@@ -589,6 +640,9 @@ to push an invalid chunk of data.
589640
The listener callback will be passed a single `Error` object.
590641

591642
##### Event: 'readable'
643+
<!-- YAML
644+
added: v0.9.4
645+
-->
592646

593647
The `'readable'` event is emitted when there is data available to be read from
594648
the stream. In some cases, attaching a listener for the `'readable'` event will
@@ -632,6 +686,9 @@ end
632686
preferred over the use of the `'readable'` event.
633687

634688
##### readable.isPaused()
689+
<!--
690+
added: v0.11.14
691+
-->
635692

636693
* Return: {Boolean}
637694

@@ -651,6 +708,9 @@ readable.isPaused() // === false
651708
```
652709

653710
##### readable.pause()
711+
<!-- YAML
712+
added: v0.9.4
713+
-->
654714

655715
* Return: `this`
656716

@@ -672,6 +732,9 @@ readable.on('data', (chunk) => {
672732
```
673733

674734
##### readable.pipe(destination[, options])
735+
<!-- YAML
736+
added: v0.9.4
737+
-->
675738

676739
* `destination` {stream.Writable} The destination for writing data
677740
* `options` {Object} Pipe options
@@ -727,6 +790,9 @@ never closed until the Node.js process exits, regardless of the specified
727790
options.
728791

729792
##### readable.read([size])
793+
<!-- YAML
794+
added: v0.9.4
795+
-->
730796

731797
* `size` {Number} Optional argument to specify how much data to read.
732798
* Return {String|Buffer|Null}
@@ -774,6 +840,9 @@ event will also be emitted.
774840
event has been emitted will return `null`. No runtime error will be raised.
775841

776842
##### readable.resume()
843+
<!-- YAML
844+
added: v0.9.4
845+
-->
777846

778847
* Return: `this`
779848

@@ -793,6 +862,9 @@ getReadableStreamSomehow()
793862
```
794863

795864
##### readable.setEncoding(encoding)
865+
<!-- YAML
866+
added: v0.9.4
867+
-->
796868

797869
* `encoding` {String} The encoding to use.
798870
* Return: `this`
@@ -825,6 +897,9 @@ readable.on('data', (chunk) => {
825897
```
826898

827899
##### readable.unpipe([destination])
900+
<!-- YAML
901+
added: v0.9.4
902+
-->
828903

829904
* `destination` {stream.Writable} Optional specific stream to unpipe
830905

@@ -851,6 +926,9 @@ setTimeout(() => {
851926
```
852927

853928
##### readable.unshift(chunk)
929+
<!-- YAML
930+
added: v0.9.11
931+
-->
854932

855933
* `chunk` {Buffer|String} Chunk of data to unshift onto the read queue
856934

@@ -911,6 +989,9 @@ appropriately, however it is best to simply avoid calling `readable.unshift()`
911989
while in the process of performing a read.
912990

913991
##### readable.wrap(stream)
992+
<!-- YAML
993+
added: v0.9.4
994+
-->
914995

915996
* `stream` {Stream} An "old style" readable stream
916997

@@ -943,6 +1024,9 @@ myReader.on('readable', () => {
9431024
### Duplex and Transform Streams
9441025

9451026
#### Class: stream.Duplex
1027+
<!-- YAML
1028+
added: v0.9.4
1029+
-->
9461030

9471031
<!--type=class-->
9481032

@@ -956,6 +1040,9 @@ Examples of Duplex streams include:
9561040
* [crypto streams][crypto]
9571041

9581042
#### Class: stream.Transform
1043+
<!-- YAML
1044+
added: v0.9.4
1045+
-->
9591046

9601047
<!--type=class-->
9611048

@@ -1579,7 +1666,7 @@ For Duplex streams, `objectMode` can be set exclusively for either the Readable
15791666
or Writable side using the `readableObjectMode` and `writableObjectMode` options
15801667
respectively.
15811668

1582-
In the following example, for instance, a new Transform stream (which is a
1669+
In the following example, for instance, a new Transform stream (which is a
15831670
type of [Duplex][] stream) is created that has an object mode Writable side
15841671
that accepts JavaScript numbers that are converted to hexidecimal strings on
15851672
the Readable side.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.