@@ -116,7 +116,7 @@ const server = http.createServer( (req, res) => {
116
116
// req is an http.IncomingMessage, which is a Readable Stream
117
117
// res is an http.ServerResponse, which is a Writable Stream
118
118
119
- var body = ' ' ;
119
+ let body = ' ' ;
120
120
// Get the data as utf8 strings.
121
121
// If an encoding is not set, Buffer objects will be received.
122
122
req .setEncoding (' utf8' );
@@ -205,10 +205,16 @@ myStream.end('done writing data');
205
205
```
206
206
207
207
#### Class: stream.Writable
208
+ <!-- YAML
209
+ added: v0.9.4
210
+ -->
208
211
209
212
<!-- type=class-->
210
213
211
214
##### Event: 'close'
215
+ <!-- YAML
216
+ added: v0.9.4
217
+ -->
212
218
213
219
The ` 'close' ` event is emitted when the stream and any of its underlying
214
220
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.
217
223
Not all Writable streams will emit the ` 'close' ` event.
218
224
219
225
##### Event: 'drain'
226
+ <!-- YAML
227
+ added: v0.9.4
228
+ -->
220
229
221
230
If a call to [ ` stream.write(chunk) ` ] [ stream-write ] returns ` false ` , the
222
231
` 'drain' ` event will be emitted when it is appropriate to resume writing data
@@ -226,7 +235,7 @@ to the stream.
226
235
// Write the data to the supplied writable stream one million times.
227
236
// Be attentive to back-pressure.
228
237
function writeOneMillionTimes (writer , data , encoding , callback ) {
229
- var i = 1000000 ;
238
+ let i = 1000000 ;
230
239
write ();
231
240
function write () {
232
241
var ok = true ;
@@ -251,6 +260,9 @@ function writeOneMillionTimes(writer, data, encoding, callback) {
251
260
```
252
261
253
262
##### Event: 'error'
263
+ <!-- YAML
264
+ added: v0.9.4
265
+ -->
254
266
255
267
* {Error}
256
268
@@ -260,6 +272,9 @@ data. The listener callback is passed a single `Error` argument when called.
260
272
* Note* : The stream is not closed when the ` 'error' ` event is emitted.
261
273
262
274
##### Event: 'finish'
275
+ <!-- YAML
276
+ added: v0.9.4
277
+ -->
263
278
264
279
The ` 'finish' ` event is emitted after the [ ` stream.end() ` ] [ stream-end ] method
265
280
has been called, and all data has been flushed to the underlying system.
@@ -276,6 +291,9 @@ writer.on('finish', () => {
276
291
```
277
292
278
293
##### Event: 'pipe'
294
+ <!-- YAML
295
+ added: v0.9.4
296
+ -->
279
297
280
298
* ` src ` {stream.Readable} source stream that is piping to this writable
281
299
@@ -293,6 +311,9 @@ reader.pipe(writer);
293
311
```
294
312
295
313
##### Event: 'unpipe'
314
+ <!-- YAML
315
+ added: v0.9.4
316
+ -->
296
317
297
318
* ` src ` {[ Readable] [ ] Stream} The source stream that
298
319
[ unpiped] [ `stream.unpipe()` ] this writable
@@ -313,6 +334,9 @@ reader.unpipe(writer);
313
334
```
314
335
315
336
##### writable.cork()
337
+ <!-- YAML
338
+ added: v0.11.2
339
+ -->
316
340
317
341
The ` writable.cork() ` method forces all written data to be buffered in memory.
318
342
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
325
349
buffered writes in a more optimized manner.
326
350
327
351
##### writable.end([ chunk] [ , encoding ] [ , callback] )
352
+ <!-- YAML
353
+ added: v0.9.4
354
+ -->
328
355
329
356
* ` chunk ` {String|Buffer|any} Optional data to write. For streams not operating
330
357
in object mode, ` chunk ` must be a string or a ` Buffer ` . For object mode
@@ -350,6 +377,9 @@ file.end('world!');
350
377
```
351
378
352
379
##### writable.setDefaultEncoding(encoding)
380
+ <!-- YAML
381
+ added: v0.11.15
382
+ -->
353
383
354
384
* ` encoding ` {String} The new default encoding
355
385
* Return: ` this `
@@ -358,6 +388,9 @@ The `writable.setDefaultEncoding()` method sets the default `encoding` for a
358
388
[ Writable] [ ] stream.
359
389
360
390
##### writable.uncork()
391
+ <!-- YAML
392
+ added: v0.11.2
393
+ -->
361
394
362
395
The ` writable.uncork() ` method flushes all data buffered since
363
396
[ ` stream.cork() ` ] [ ] was called.
@@ -391,6 +424,9 @@ process.nextTick(() => {
391
424
```
392
425
393
426
##### writable.write(chunk[ , encoding] [ , callback ] )
427
+ <!-- YAML
428
+ added: v0.9.4
429
+ -->
394
430
395
431
* ` chunk ` {String|Buffer} The data to write
396
432
* ` 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
516
552
use the [ ` EventEmitter ` ] [ ] and ` readable.pause() ` /` readable.resume() ` APIs.
517
553
518
554
#### Class: stream.Readable
555
+ <!-- YAML
556
+ added: v0.9.4
557
+ -->
519
558
520
559
<!-- type=class-->
521
560
522
561
##### Event: 'close'
562
+ <!-- YAML
563
+ added: v0.9.4
564
+ -->
523
565
524
566
The ` 'close' ` event is emitted when the stream and any of its underlying
525
567
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.
528
570
Not all [ Readable] [ ] streams will emit the ` 'close' ` event.
529
571
530
572
##### Event: 'data'
573
+ <!-- YAML
574
+ added: v0.9.4
575
+ -->
531
576
532
577
* ` chunk ` {Buffer|String|any} The chunk of data. For streams that are not
533
578
operating in object mode, the chunk will be either a string or ` Buffer ` .
@@ -558,6 +603,9 @@ readable.on('data', (chunk) => {
558
603
```
559
604
560
605
##### Event: 'end'
606
+ <!-- YAML
607
+ added: v0.9.4
608
+ -->
561
609
562
610
The ` 'end' ` event is emitted when there is no more data to be consumed from
563
611
the stream.
@@ -578,6 +626,9 @@ readable.on('end', () => {
578
626
```
579
627
580
628
##### Event: 'error'
629
+ <!-- YAML
630
+ added: v0.9.4
631
+ -->
581
632
582
633
* {Error}
583
634
@@ -589,6 +640,9 @@ to push an invalid chunk of data.
589
640
The listener callback will be passed a single ` Error ` object.
590
641
591
642
##### Event: 'readable'
643
+ <!-- YAML
644
+ added: v0.9.4
645
+ -->
592
646
593
647
The ` 'readable' ` event is emitted when there is data available to be read from
594
648
the stream. In some cases, attaching a listener for the ` 'readable' ` event will
632
686
preferred over the use of the ` 'readable' ` event.
633
687
634
688
##### readable.isPaused()
689
+ <!--
690
+ added: v0.11.14
691
+ -->
635
692
636
693
* Return: {Boolean}
637
694
@@ -651,6 +708,9 @@ readable.isPaused() // === false
651
708
```
652
709
653
710
##### readable.pause()
711
+ <!-- YAML
712
+ added: v0.9.4
713
+ -->
654
714
655
715
* Return: ` this `
656
716
@@ -672,6 +732,9 @@ readable.on('data', (chunk) => {
672
732
```
673
733
674
734
##### readable.pipe(destination[ , options] )
735
+ <!-- YAML
736
+ added: v0.9.4
737
+ -->
675
738
676
739
* ` destination ` {stream.Writable} The destination for writing data
677
740
* ` options ` {Object} Pipe options
@@ -727,6 +790,9 @@ never closed until the Node.js process exits, regardless of the specified
727
790
options.
728
791
729
792
##### readable.read([ size] )
793
+ <!-- YAML
794
+ added: v0.9.4
795
+ -->
730
796
731
797
* ` size ` {Number} Optional argument to specify how much data to read.
732
798
* Return {String|Buffer|Null}
@@ -774,6 +840,9 @@ event will also be emitted.
774
840
event has been emitted will return ` null ` . No runtime error will be raised.
775
841
776
842
##### readable.resume()
843
+ <!-- YAML
844
+ added: v0.9.4
845
+ -->
777
846
778
847
* Return: ` this `
779
848
@@ -793,6 +862,9 @@ getReadableStreamSomehow()
793
862
```
794
863
795
864
##### readable.setEncoding(encoding)
865
+ <!-- YAML
866
+ added: v0.9.4
867
+ -->
796
868
797
869
* ` encoding ` {String} The encoding to use.
798
870
* Return: ` this `
@@ -825,6 +897,9 @@ readable.on('data', (chunk) => {
825
897
```
826
898
827
899
##### readable.unpipe([ destination] )
900
+ <!-- YAML
901
+ added: v0.9.4
902
+ -->
828
903
829
904
* ` destination ` {stream.Writable} Optional specific stream to unpipe
830
905
@@ -851,6 +926,9 @@ setTimeout(() => {
851
926
```
852
927
853
928
##### readable.unshift(chunk)
929
+ <!-- YAML
930
+ added: v0.9.11
931
+ -->
854
932
855
933
* ` chunk ` {Buffer|String} Chunk of data to unshift onto the read queue
856
934
@@ -911,6 +989,9 @@ appropriately, however it is best to simply avoid calling `readable.unshift()`
911
989
while in the process of performing a read.
912
990
913
991
##### readable.wrap(stream)
992
+ <!-- YAML
993
+ added: v0.9.4
994
+ -->
914
995
915
996
* ` stream ` {Stream} An "old style" readable stream
916
997
@@ -943,6 +1024,9 @@ myReader.on('readable', () => {
943
1024
### Duplex and Transform Streams
944
1025
945
1026
#### Class: stream.Duplex
1027
+ <!-- YAML
1028
+ added: v0.9.4
1029
+ -->
946
1030
947
1031
<!-- type=class-->
948
1032
@@ -956,6 +1040,9 @@ Examples of Duplex streams include:
956
1040
* [ crypto streams] [ crypto ]
957
1041
958
1042
#### Class: stream.Transform
1043
+ <!-- YAML
1044
+ added: v0.9.4
1045
+ -->
959
1046
960
1047
<!-- type=class-->
961
1048
@@ -1579,7 +1666,7 @@ For Duplex streams, `objectMode` can be set exclusively for either the Readable
1579
1666
or Writable side using the ` readableObjectMode ` and ` writableObjectMode ` options
1580
1667
respectively.
1581
1668
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
1583
1670
type of [ Duplex] [ ] stream) is created that has an object mode Writable side
1584
1671
that accepts JavaScript numbers that are converted to hexidecimal strings on
1585
1672
the Readable side.
0 commit comments