对象模式


🌐 Object mode

由 Node.js API 创建的所有流都仅操作字符串和 Buffer(或 Uint8Array)对象。然而,流的实现也可以处理其他类型的 JavaScript 值(null 除外,它在流中具有特殊用途)。这种流被认为是在“对象模式”下操作的。

🌐 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".

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

🌐 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.