调用 `readable.setEncoding()` 之后 `highWaterMark` 的差异


使用 readable.setEncoding() 会改变 highWaterMark 属性在非对象模式中的作用。

一般而言,当前缓冲的大小是以字节为单位跟 highWaterMark 比较的。 但是调用 setEncoding() 之后,会开始以字符为单位进行比较。

大多数情况下,使用 latin1ascii 时是没有问题的。 但在处理含有多字节字符的字符串时,需要小心。

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.