写入器接口


🌐 Writer interface

作家是任何符合 Writer 接口的对象。只有 write() 是必需的;所有其他方法都是可选的。

🌐 A writer is any object conforming to the Writer interface. Only write() is required; all other methods are optional.

每个异步方法都有一个同步的 *Sync 对应方法,设计用于尝试-回退模式:首先尝试快速的同步路径,只有当同步调用表明无法完成时才回退到异步版本:

🌐 Each async method has a synchronous *Sync counterpart designed for a try-fallback pattern: attempt the fast synchronous path first, and fall back to the async version only when the synchronous call indicates it could not complete:

if (!writer.writeSync(chunk)) await writer.write(chunk);
if (!writer.writevSync(chunks)) await writer.writev(chunks);
if (writer.endSync() < 0) await writer.end();
writer.fail(err);  // Always synchronous, no fallback needed