writable.cork()


writable.cork() 方法强制所有写入的数据都缓存在内存中。 当调用 stream.uncork()stream.end() 方法时,缓冲的数据将被刷新。

writable.cork() 的主要目的是适应将几个小块快速连续写入流的情况。 writable.cork() 不是立即将它们转发到底层目标,而是缓冲所有块,直到 writable.uncork() 被调用,如果存在,writable.uncork() 会将它们全部传给 writable._writev()。 这可以防止在等待处理第一个小块时正在缓冲数据的行头阻塞情况。 但是,在不实现 writable._writev() 的情况下使用 writable.cork() 可能会对吞吐量产生不利影响。

另请参阅:writable.uncork()writable._writev()

The writable.cork() method forces all written data to be buffered in memory. The buffered data will be flushed when either the stream.uncork() or stream.end() methods are called.

The primary intent of writable.cork() is to accommodate a situation in which several small chunks are written to the stream in rapid succession. Instead of immediately forwarding them to the underlying destination, writable.cork() buffers all the chunks until writable.uncork() is called, which will pass them all to writable._writev(), if present. This prevents a head-of-line blocking situation where data is being buffered while waiting for the first small chunk to be processed. However, use of writable.cork() without implementing writable._writev() may have an adverse effect on throughput.

See also: writable.uncork(), writable._writev().