对象模式


Node.js API 创建的所有流都只对字符串和 Buffer(或 Uint8Array)对象进行操作。 但是,流的实现可以使用其他类型的 JavaScript 值(除了 null,它在流中具有特殊用途)。 这样的流被认为是在"对象模式"下运行的。

流的实例在创建流时使用 objectMode 选项切换到对象模式。 尝试将现有的流切换到对象模式是不安全的。

All streams created by Node.js APIs operate exclusively on strings and Buffer (or Uint8Array) objects. It is possible, however, for stream implementations to work with other types of JavaScript values (with the exception of null, which serves a special purpose within streams). Such streams are considered to operate in "object mode".

Stream instances are switched into object mode using the objectMode option when the stream is created. Attempting to switch an existing stream into object mode is not safe.