Skip to main content
Module

std/node/stream.ts>Writable#uncork

Deno standard library
Go to Latest
method Writable.prototype.uncork
import { Writable } from "https://deno.land/std@0.147.0/node/stream.ts";

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

When using writable.cork() and writable.uncork() to manage the buffering of writes to a stream, it is recommended that calls to writable.uncork() be deferred using process.nextTick(). Doing so allows batching of allwritable.write() calls that occur within a given Node.js event loop phase.

stream.cork();
stream.write('some ');
stream.write('data ');
process.nextTick(() => stream.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();
});

See also: writable.cork().