@@ -68,8 +68,8 @@ buffer that can be retrieved using `writable._writableState.getBuffer()` or
68
68
69
69
The amount of data potentially buffered depends on the ` highWaterMark ` option
70
70
passed into the streams constructor. For normal streams, the ` highWaterMark `
71
- option specifies a total number of bytes. For streams operating in object mode,
72
- the ` highWaterMark ` specifies a total number of objects.
71
+ option specifies a [ total number of bytes] [ hwm-gotcha ] . For streams operating
72
+ in object mode, the ` highWaterMark ` specifies a total number of objects.
73
73
74
74
Data is buffered in Readable streams when the implementation calls
75
75
[ ` stream.push(chunk) ` ] [ stream-push ] . If the consumer of the Stream does not
@@ -1517,9 +1517,9 @@ constructor and implement the `readable._read()` method.
1517
1517
#### new stream.Readable([ options] )
1518
1518
1519
1519
* ` options ` {Object}
1520
- * ` highWaterMark ` {number} The maximum number of bytes to store in
1521
- the internal buffer before ceasing to read from the underlying
1522
- resource. Defaults to ` 16384 ` (16kb), or ` 16 ` for ` objectMode ` streams
1520
+ * ` highWaterMark ` {number} The maximum [ number of bytes] [ hwm-gotcha ] to store
1521
+ in the internal buffer before ceasing to read from the underlying resource.
1522
+ Defaults to ` 16384 ` (16kb), or ` 16 ` for ` objectMode ` streams
1523
1523
* ` encoding ` {string} If specified, then buffers will be decoded to
1524
1524
strings using the specified encoding. Defaults to ` null `
1525
1525
* ` objectMode ` {boolean} Whether this stream should behave
@@ -2157,6 +2157,19 @@ object mode has an interesting side effect. Because it *is* a call to
2157
2157
However, because the argument is an empty string, no data is added to the
2158
2158
readable buffer so there is nothing for a user to consume.
2159
2159
2160
+ ### ` highWaterMark ` discrepency after calling ` readable.setEncoding() `
2161
+
2162
+ The use of ` readable.setEncoding() ` will change the behavior of how the
2163
+ ` highWaterMark ` operates in non-object mode.
2164
+
2165
+ Typically, the size of the current buffer is measured against the
2166
+ ` highWaterMark ` in _ bytes_ . However, after ` setEncoding() ` is called, the
2167
+ comparison function will begin to measure the buffer's size in _ characters_ .
2168
+
2169
+ This is not a problem in common cases with ` latin1 ` or ` ascii ` . But it is
2170
+ advised to be mindful about this behavior when working with strings that could
2171
+ contain multi-byte characters.
2172
+
2160
2173
[ `'data'` ] : #stream_event_data
2161
2174
[ `'drain'` ] : #stream_event_drain
2162
2175
[ `'end'` ] : #stream_event_end
@@ -2195,6 +2208,8 @@ readable buffer so there is nothing for a user to consume.
2195
2208
[ fs write streams ] : fs.html#fs_class_fs_writestream
2196
2209
[ http-incoming-message ] : http.html#http_class_http_incomingmessage
2197
2210
[ zlib ] : zlib.html
2211
+ [ hwm-gotcha ] : #stream_highWaterMark_discrepency_after_calling_readable_setencoding
2212
+ [ Readable ] : #stream_class_stream_readable
2198
2213
[ stream-_flush ] : #stream_transform_flush_callback
2199
2214
[ stream-_read ] : #stream_readable_read_size_1
2200
2215
[ stream-_transform ] : #stream_transform_transform_chunk_encoding_callback
0 commit comments