调用 `readable.setEncoding()` 之后 `highWaterMark` 的差异
readable.setEncoding()
的使用将改变 highWaterMark
在非对象模式下的操作方式。
通常,当前缓冲区的大小是根据 highWaterMark
以字节为单位来衡量的。
但是,在调用 setEncoding()
之后,比较函数将开始以字符为单位测量缓冲区的大小。
在 latin1
或 ascii
的常见情况下,这不是问题。
但建议在处理可能包含多字节字符的字符串时注意这种行为。
The use of readable.setEncoding()
will change the behavior of how the
highWaterMark
operates in non-object mode.
Typically, the size of the current buffer is measured against the
highWaterMark
in bytes. However, after setEncoding()
is called, the
comparison function will begin to measure the buffer's size in characters.
This is not a problem in common cases with latin1
or ascii
. But it is
advised to be mindful about this behavior when working with strings that could
contain multi-byte characters.