writable.uncork()


writable.uncork() 方法会刷新自 stream.cork() 被调用以来缓冲的所有数据。

🌐 The writable.uncork() method flushes all data buffered since stream.cork() was called.

在使用 writable.cork()writable.uncork() 来管理对流的写入缓冲时,使用 process.nextTick() 来延迟调用 writable.uncork()。这样可以将所有在特定 Node.js 事件循环阶段发生的 writable.write() 调用进行批处理。

🌐 When using writable.cork() and writable.uncork() to manage the buffering of writes to a stream, defer calls to writable.uncork() using process.nextTick(). Doing so allows batching of all writable.write() calls that occur within a given Node.js event loop phase.

stream.cork();
stream.write('some ');
stream.write('data ');
process.nextTick(() => stream.uncork()); 

如果在同一个流上多次调用 writable.cork() 方法,则必须调用相同次数的 writable.uncork() 来刷新缓冲的数据。

🌐 If the writable.cork() method is called multiple times on a stream, the same number of calls to writable.uncork() must be called to flush the buffered data.

stream.cork();
stream.write('some ');
stream.cork();
stream.write('data ');
process.nextTick(() => {
  stream.uncork();
  // The data will not be flushed until uncork() is called a second time.
  stream.uncork();
}); 

另请参见:writable.cork()

🌐 See also: writable.cork().