@@ -37,14 +37,14 @@ and properties depending on whether they are Readable, Writable, or
37
37
Duplex.
38
38
39
39
If a stream is both Readable and Writable, then it implements all of
40
- the methods and events below . So, a [ Duplex] [ ] or [ Transform] [ ] stream is
40
+ the methods and events. So, a [ Duplex] [ ] or [ Transform] [ ] stream is
41
41
fully described by this API, though their implementation may be
42
42
somewhat different.
43
43
44
44
It is not necessary to implement Stream interfaces in order to consume
45
45
streams in your programs. If you ** are** implementing streaming
46
46
interfaces in your own program, please also refer to
47
- [ API for Stream Implementors] [ ] below .
47
+ [ API for Stream Implementors] [ ] .
48
48
49
49
Almost all Node.js programs, no matter how simple, use Streams in some
50
50
way. Here is an example of using Streams in an Node.js program:
@@ -95,7 +95,7 @@ server.listen(1337);
95
95
### Class: stream.Duplex
96
96
97
97
Duplex streams are streams that implement both the [ Readable] [ ] and
98
- [ Writable] [ ] interfaces. See above for usage.
98
+ [ Writable] [ ] interfaces.
99
99
100
100
Examples of Duplex streams include:
101
101
@@ -464,8 +464,8 @@ Note that `stream.unshift(chunk)` cannot be called after the `'end'` event
464
464
has been triggered; a runtime error will be raised.
465
465
466
466
If you find that you must often call ` stream.unshift(chunk) ` in your
467
- programs, consider implementing a [ Transform] [ ] stream instead. (See API
468
- for Stream Implementors, below .)
467
+ programs, consider implementing a [ Transform] [ ] stream instead. (See [ API
468
+ for Stream Implementors] [ ] .)
469
469
470
470
``` javascript
471
471
// Pull off a header delimited by \n\n
@@ -514,7 +514,7 @@ reading state appropriately, however it is best to simply avoid calling
514
514
* ` stream ` {Stream} An "old style" readable stream
515
515
516
516
Versions of Node.js prior to v0.10 had streams that did not implement the
517
- entire Streams API as it is today. (See " Compatibility" below for
517
+ entire Streams API as it is today. (See [ Compatibility] [ ] for
518
518
more information.)
519
519
520
520
If you are using an older Node.js library that emits ` 'data' ` events and
@@ -542,7 +542,7 @@ myReader.on('readable', () => {
542
542
543
543
Transform streams are [ Duplex] [ ] streams where the output is in some way
544
544
computed from the input. They implement both the [ Readable] [ ] and
545
- [ Writable] [ ] interfaces. See above for usage.
545
+ [ Writable] [ ] interfaces.
546
546
547
547
Examples of Transform streams include:
548
548
@@ -789,7 +789,7 @@ of stream class you are writing:
789
789
</table >
790
790
791
791
In your implementation code, it is very important to never call the
792
- methods described in [ API for Stream Consumers] [ ] above . Otherwise, you
792
+ methods described in [ API for Stream Consumers] [ ] . Otherwise, you
793
793
can potentially cause adverse side effects in programs that consume
794
794
your streaming interfaces.
795
795
@@ -843,7 +843,7 @@ it can come in handy as a building block for novel sorts of streams.
843
843
` stream.Readable ` is an abstract class designed to be extended with an
844
844
underlying implementation of the [ ` _read(size) ` ] [ ] method.
845
845
846
- Please see above under [ API for Stream Consumers] [ ] for how to consume
846
+ Please see [ API for Stream Consumers] [ ] for how to consume
847
847
streams in your programs. What follows is an explanation of how to
848
848
implement Readable streams in your programs.
849
849
@@ -979,12 +979,13 @@ Counter.prototype._read = function() {
979
979
980
980
#### Example: SimpleProtocol v1 (Sub-optimal)
981
981
982
- This is similar to the ` parseHeader ` function described above, but
983
- implemented as a custom stream. Also, note that this implementation
984
- does not convert the incoming data to a string.
982
+ This is similar to the ` parseHeader ` function described
983
+ [ here] ( #stream_readable_unshift_chunk ) , but implemented as a custom stream.
984
+ Also, note that this implementation does not convert the incoming data to a
985
+ string.
985
986
986
987
However, this would be better implemented as a [ Transform] [ ] stream. See
987
- below for a better implementation.
988
+ [ SimpleProtocol v2 ] [ ] for a better implementation.
988
989
989
990
``` javascript
990
991
// A parser for a simple data protocol.
@@ -1201,9 +1202,10 @@ your own extension classes.
1201
1202
1202
1203
#### Example: ` SimpleProtocol ` parser v2
1203
1204
1204
- The example above of a simple protocol parser can be implemented
1205
- simply by using the higher level [ Transform] [ ] stream class, similar to
1206
- the ` parseHeader ` and ` SimpleProtocol v1 ` examples above.
1205
+ The example [ here] ( #stream_example_simpleprotocol_v1_sub_optimal ) of a simple
1206
+ protocol parser can be implemented simply by using the higher level
1207
+ [ Transform] [ ] stream class, similar to the ` parseHeader ` and `SimpleProtocol
1208
+ v1` examples.
1207
1209
1208
1210
In this example, rather than providing the input as an argument, it
1209
1211
would be piped into the parser, which is a more idiomatic Node.js stream
@@ -1284,7 +1286,7 @@ SimpleProtocol.prototype._transform = function(chunk, encoding, done) {
1284
1286
` stream.Writable ` is an abstract class designed to be extended with an
1285
1287
underlying implementation of the [ ` _write(chunk, encoding, callback) ` ] [ ] method.
1286
1288
1287
- Please see above under [ API for Stream Consumers] [ ] for how to consume
1289
+ Please see [ API for Stream Consumers] [ ] for how to consume
1288
1290
writable streams in your programs. What follows is an explanation of
1289
1291
how to implement Writable streams in your programs.
1290
1292
@@ -1500,7 +1502,7 @@ simpler, but also less powerful and less useful.
1500
1502
meant that you still had to be prepared to receive ` 'data' ` events
1501
1503
even when the stream was in a paused state.
1502
1504
1503
- In Node.js v0.10, the Readable class described below was added.
1505
+ In Node.js v0.10, the [ Readable] [ ] class was added.
1504
1506
For backwards compatibility with older Node.js programs, Readable streams
1505
1507
switch into "flowing mode" when a ` 'data' ` event handler is added, or
1506
1508
when the [ ` resume() ` ] [ ] method is called. The effect is that, even if
@@ -1710,6 +1712,7 @@ horribly wrong.
1710
1712
[ API for Stream Implementors ] : #stream_api_for_stream_implementors
1711
1713
[ child process stdin ] : child_process.html#child_process_child_stdin
1712
1714
[ child process stdout and stderr ] : child_process.html#child_process_child_stdout
1715
+ [ Compatibility ] : #stream_compatibility_with_older_node_js_versions
1713
1716
[ crypto streams ] : crypto.html
1714
1717
[ crypto ] : crypto.html
1715
1718
[ Duplex ] : #stream_class_stream_duplex
@@ -1722,6 +1725,7 @@ horribly wrong.
1722
1725
[ Object mode ] : #stream_object_mode
1723
1726
[ Readable ] : #stream_class_stream_readable
1724
1727
[ request to an HTTP server ] : http.html#http_http_incomingmessage
1728
+ [ SimpleProtocol v2 ] : #stream_example_simpleprotocol_parser_v2
1725
1729
[ tcp sockets ] : net.html#net_class_net_socket
1726
1730
[ Transform ] : #stream_class_stream_transform
1727
1731
[ unpiped ] : #stream_readable_unpipe_destination
0 commit comments