Streams

writable.cork() and uncork()

Temporarily buffers writes so small pieces may be handled together, particularly with a custom writev implementation. Balance each cork call with an uncork call; it is not compression, and buffering without a bound increases memory use. Tested on Node.js 22.16.0. Example output (one line per entry): ["a|b"].

Formal Syntax & Structure

nodejs syntaxnodejs
writable.cork(); writable.uncork()

Return Value

undefined

No value from either call.

Working Example

Example Snippetnodejs
import { Writable } from 'node:stream';import { finished } from 'node:stream/promises';const w = new Writable({ write(c, e, cb) { console.log(c.toString()); cb(); }, writev(chunks, cb) { console.log(chunks.map(x => x.chunk.toString()).join('|')); cb(); } });w.cork();w.write('a');w.write('b');w.uncork();w.end();await finished(w, { cleanup: true });
Node.js Reference