@@ -66,8 +66,8 @@ buffer that can be retrieved using `writable._writableState.getBuffer()` or
66
66
67
67
The amount of data potentially buffered depends on the ` highWaterMark ` option
68
68
passed into the streams constructor. For normal streams, the ` highWaterMark `
69
- option specifies a total number of bytes. For streams operating in object mode,
70
- the ` highWaterMark ` specifies a total number of objects.
69
+ option specifies a [ total number of bytes] [ hwm-gotcha ] . For streams operating
70
+ in object mode, the ` highWaterMark ` specifies a total number of objects.
71
71
72
72
Data is buffered in Readable streams when the implementation calls
73
73
[ ` stream.push(chunk) ` ] [ stream-push ] . If the consumer of the Stream does not
@@ -1415,9 +1415,9 @@ constructor and implement the `readable._read()` method.
1415
1415
#### new stream.Readable([ options] )
1416
1416
1417
1417
* ` options ` {Object}
1418
- * ` highWaterMark ` {number} The maximum number of bytes to store in
1419
- the internal buffer before ceasing to read from the underlying
1420
- resource. Defaults to ` 16384 ` (16kb), or ` 16 ` for ` objectMode ` streams
1418
+ * ` highWaterMark ` {number} The maximum [ number of bytes] [ hwm-gotcha ] to store
1419
+ in the internal buffer before ceasing to read from the underlying resource.
1420
+ Defaults to ` 16384 ` (16kb), or ` 16 ` for ` objectMode ` streams
1421
1421
* ` encoding ` {string} If specified, then buffers will be decoded to
1422
1422
strings using the specified encoding. Defaults to ` null `
1423
1423
* ` objectMode ` {boolean} Whether this stream should behave
@@ -2031,6 +2031,19 @@ has an interesting side effect. Because it *is* a call to
2031
2031
However, because the argument is an empty string, no data is added to the
2032
2032
readable buffer so there is nothing for a user to consume.
2033
2033
2034
+ ### ` highWaterMark ` discrepency after calling ` readable.setEncoding() `
2035
+
2036
+ The use of ` readable.setEncoding() ` will change the behavior of how the
2037
+ ` highWaterMark ` operates in non-object mode.
2038
+
2039
+ Typically, the size of the current buffer is measured against the
2040
+ ` highWaterMark ` in _ bytes_ . However, after ` setEncoding() ` is called, the
2041
+ comparison function will begin to measure the buffer's size in _ characters_ .
2042
+
2043
+ This is not a problem in common cases with ` latin1 ` or ` ascii ` . But it is
2044
+ advised to be mindful about this behavior when working with strings that could
2045
+ contain multi-byte characters.
2046
+
2034
2047
[ `'data'` ] : #stream_event_data
2035
2048
[ `'drain'` ] : #stream_event_drain
2036
2049
[ `'end'` ] : #stream_event_end
@@ -2065,6 +2078,8 @@ readable buffer so there is nothing for a user to consume.
2065
2078
[ http-incoming-message ] : http.html#http_class_http_incomingmessage
2066
2079
[ Readable ] : #stream_class_stream_readable
2067
2080
[ zlib ] : zlib.html
2081
+ [ hwm-gotcha ] : #stream_highWaterMark_discrepency_after_calling_readable_setencoding
2082
+ [ Readable ] : #stream_class_stream_readable
2068
2083
[ stream-_flush ] : #stream_transform_flush_callback
2069
2084
[ stream-_read ] : #stream_readable_read_size_1
2070
2085
[ stream-_transform ] : #stream_transform_transform_chunk_encoding_callback
0 commit comments