Skip to content

WriteStream

Defined in: src/node/streams.ts:90

A WriteStream implementation that wraps an underlying global WritableStream.

  • Writable
  • WriteStream

new WriteStream(opts?, handleOrPromise): WriteStream

Defined in: src/node/streams.ts:97

CreateWriteStreamOptions = {}

FileHandle | Promise<FileHandle>

WriteStream

Writable.constructor

_events: Listeners

Defined in: node_modules/@zenfs/streams/dist/events.d.ts:28

Writable._events


_eventsCount: number

Defined in: node_modules/@zenfs/streams/dist/events.d.ts:29

Writable._eventsCount


optional _maxListeners?: number

Defined in: node_modules/@zenfs/streams/dist/events.d.ts:30

Writable._maxListeners


optional _readableState?: ReadableState

Defined in: node_modules/@zenfs/streams/dist/writable.d.ts:126

Present on a Duplex; undefined on a plain Writable.

Writable._readableState


_writableState: WritableState

Defined in: node_modules/@zenfs/streams/dist/writable.d.ts:124

Writable._writableState


protected [kCapture]: boolean

Defined in: node_modules/@zenfs/streams/dist/events.d.ts:31

Writable.[kCapture]


pending: boolean = true

Defined in: src/node/streams.ts:91

This property is true if the underlying file has not been opened yet, i.e. before the 'ready' event is emitted.

v11.2.0

fs.WriteStream.pending


static captureRejections: boolean

Defined in: node_modules/@zenfs/streams/dist/events.d.ts:25

The default for the captureRejections option of newly created emitters.

Writable.captureRejections


readonly static captureRejectionSymbol: typeof captureRejectionSymbol

Defined in: node_modules/@zenfs/streams/dist/events.d.ts:26

Writable.captureRejectionSymbol


static defaultMaxListeners: number

Defined in: node_modules/@zenfs/streams/dist/events.d.ts:23

Writable.defaultMaxListeners


readonly static errorMonitor: typeof errorMonitor

Defined in: node_modules/@zenfs/streams/dist/events.d.ts:27

Writable.errorMonitor


readonly static WritableState: typeof WritableState

Defined in: node_modules/@zenfs/streams/dist/writable.d.ts:128

Writable.WritableState

get bytesWritten(): number

Defined in: src/node/streams.ts:154

The number of bytes written so far. Does not include data that is still queued for writing.

v0.4.7

number

fs.WriteStream.bytesWritten


get closed(): boolean

Defined in: node_modules/@zenfs/streams/dist/writable.d.ts:145

Is true after 'close' has been emitted.

v18.0.0

boolean

fs.WriteStream.closed

Writable.closed


get destroyed(): boolean

Defined in: node_modules/@zenfs/streams/dist/writable.d.ts:146

Is true after writable.destroy() has been called.

v8.0.0

boolean

set destroyed(value): void

Defined in: node_modules/@zenfs/streams/dist/writable.d.ts:147

Is true after writable.destroy() has been called.

v8.0.0

boolean

void

fs.WriteStream.destroyed

Writable.destroyed


get errored(): Error | null

Defined in: node_modules/@zenfs/streams/dist/writable.d.ts:158

Returns error if the stream has been destroyed with an error.

v18.0.0

Error | null

fs.WriteStream.errored

Writable.errored


get path(): string

Defined in: src/node/streams.ts:150

The path to the file the stream is writing to as specified in the first argument to createWriteStream. If path is passed as a string, thenwriteStream.path will be a string. If path is passed as a Buffer, thenwriteStream.path will be a Buffer.

v0.1.93

string

fs.WriteStream.path


get writable(): boolean

Defined in: node_modules/@zenfs/streams/dist/writable.d.ts:148

Is true if it is safe to call writable.write(), which means the stream has not been destroyed, errored, or ended.

v11.4.0

boolean

set writable(value): void

Defined in: node_modules/@zenfs/streams/dist/writable.d.ts:149

Is true if it is safe to call writable.write(), which means the stream has not been destroyed, errored, or ended.

v11.4.0

boolean

void

fs.WriteStream.writable

Writable.writable


get writableAborted(): boolean

Defined in: node_modules/@zenfs/streams/dist/writable.d.ts:159

Returns whether the stream was destroyed or errored before emitting 'finish'.

v18.0.0, v16.17.0

boolean

fs.WriteStream.writableAborted

Writable.writableAborted


get writableBuffer(): BufferedWrite[] | undefined

Defined in: node_modules/@zenfs/streams/dist/writable.d.ts:152

BufferedWrite[] | undefined

Writable.writableBuffer


get writableCorked(): number

Defined in: node_modules/@zenfs/streams/dist/writable.d.ts:156

Number of times writable.uncork() needs to be called in order to fully uncork the stream.

v13.2.0, v12.16.0

number

fs.WriteStream.writableCorked

Writable.writableCorked


get writableEnded(): boolean

Defined in: node_modules/@zenfs/streams/dist/writable.d.ts:153

Is true after writable.end() has been called. This property does not indicate whether the data has been flushed, for this use writable.writableFinished instead.

v12.9.0

boolean

fs.WriteStream.writableEnded

Writable.writableEnded


get writableFinished(): boolean

Defined in: node_modules/@zenfs/streams/dist/writable.d.ts:150

Is set to true immediately before the 'finish' event is emitted.

v12.6.0

boolean

fs.WriteStream.writableFinished

Writable.writableFinished


get writableHighWaterMark(): number

Defined in: node_modules/@zenfs/streams/dist/writable.d.ts:155

Return the value of highWaterMark passed when creating this Writable.

v9.3.0

number

fs.WriteStream.writableHighWaterMark

Writable.writableHighWaterMark


get writableLength(): number

Defined in: node_modules/@zenfs/streams/dist/writable.d.ts:157

This property contains the number of bytes (or objects) in the queue ready to be written. The value provides introspection data regarding the status of the highWaterMark.

v9.4.0

number

fs.WriteStream.writableLength

Writable.writableLength


get writableNeedDrain(): boolean

Defined in: node_modules/@zenfs/streams/dist/writable.d.ts:154

Is true if the stream’s buffer has been full and stream will emit 'drain'.

v15.2.0, v14.17.0

boolean

fs.WriteStream.writableNeedDrain

Writable.writableNeedDrain


get writableObjectMode(): boolean

Defined in: node_modules/@zenfs/streams/dist/writable.d.ts:151

Getter for the property objectMode of a given Writable stream.

v12.3.0

boolean

fs.WriteStream.writableObjectMode

Writable.writableObjectMode

optional _construct(callback): void

Defined in: node_modules/@zenfs/streams/dist/writable.d.ts:141

Callback

void

fs.WriteStream._construct

Writable._construct


_destroy(error, callback): void

Defined in: node_modules/@zenfs/streams/dist/writable.d.ts:162

Error | null

Callback

void

fs.WriteStream._destroy

Writable._destroy


_final(callback): Promise<void>

Defined in: src/node/streams.ts:127

(error?) => void

Promise<void>

fs.WriteStream._final

Writable._final


_undestroy(): void

Defined in: node_modules/@zenfs/streams/dist/writable.d.ts:161

void

Writable._undestroy


_write(chunk, encoding, callback): Promise<void>

Defined in: src/node/streams.ts:110

any

"buffer" | BufferEncoding

(error?) => void

Promise<void>

fs.WriteStream._write

Writable._write


optional _writev(chunks, callback): void

Defined in: node_modules/@zenfs/streams/dist/writable.d.ts:140

WriteRequest[]

Callback

void

fs.WriteStream._writev

Writable._writev


[asyncDispose](): Promise<void>

Defined in: node_modules/@zenfs/streams/dist/writable.d.ts:168

Promise<void>

fs.WriteStream.[asyncDispose]

Writable.[asyncDispose]


[captureRejectionSymbol](err): void

Defined in: node_modules/@zenfs/streams/dist/writable.d.ts:163

Error

void

Writable.[captureRejectionSymbol]


addListener(type, listener): this

Defined in: node_modules/@zenfs/streams/dist/events.d.ts:36

EventKey

Listener

this

fs.WriteStream.addListener

Writable.addListener


close(callback?): void

Defined in: src/node/streams.ts:140

Closes writeStream. Optionally accepts a callback that will be executed once the writeStreamis closed.

Callback<[void]> = ...

void

v0.9.4

fs.WriteStream.close


cork(): void

Defined in: node_modules/@zenfs/streams/dist/writable.d.ts:136

Buffers writes until a matching number of uncork() calls.

void

fs.WriteStream.cork

Writable.cork


destroy(error?, callback?): this

Defined in: node_modules/@zenfs/streams/dist/writable.d.ts:160

Error | null

Callback

this

fs.WriteStream.destroy

Writable.destroy


emit(type, …args): boolean

Defined in: node_modules/@zenfs/streams/dist/events.d.ts:35

EventKey

…any[]

boolean

fs.WriteStream.emit

Writable.emit


end(callback?): this

Defined in: node_modules/@zenfs/streams/dist/writable.d.ts:142

Calling the writable.end() method signals that no more data will be written to the Writable. The optional chunk and encoding arguments allow one final additional chunk of data to be written immediately before closing the stream.

Calling the write method after calling end will raise an error.

// Write 'hello, ' and then end with 'world!'.
import fs from 'node:fs';
const file = fs.createWriteStream('example.txt');
file.write('hello, ');
file.end('world!');
// Writing more now is not allowed!

Callback

this

v0.9.4

fs.WriteStream.end

Writable.end

end(chunk, callback?): this

Defined in: node_modules/@zenfs/streams/dist/writable.d.ts:143

Signals that no more data will be written, with one final chunk of data.

any

Optional data to write. For streams not operating in object mode, chunk must be a {string}, {Buffer}, {TypedArray} or {DataView}. For object mode streams, chunk may be any JavaScript value other than null.

Callback

this

Writable.end for full details.

v0.9.4

fs.WriteStream.end

Writable.end

end(chunk, encoding?, callback?): this

Defined in: node_modules/@zenfs/streams/dist/writable.d.ts:144

Signals that no more data will be written, with one final chunk of data.

any

Optional data to write. For streams not operating in object mode, chunk must be a {string}, {Buffer}, {TypedArray} or {DataView}. For object mode streams, chunk may be any JavaScript value other than null.

BufferEncoding | null

The encoding if chunk is a string

Callback

this

Writable.end for full details.

v0.9.4

fs.WriteStream.end

Writable.end


eventNames(): EventKey[]

Defined in: node_modules/@zenfs/streams/dist/events.d.ts:47

EventKey[]

fs.WriteStream.eventNames

Writable.eventNames


getMaxListeners(): number

Defined in: node_modules/@zenfs/streams/dist/events.d.ts:34

number

fs.WriteStream.getMaxListeners

Writable.getMaxListeners


listenerCount(type, listener?): number

Defined in: node_modules/@zenfs/streams/dist/events.d.ts:46

EventKey

Listener

number

fs.WriteStream.listenerCount

Writable.listenerCount


listeners(type): Listener[]

Defined in: node_modules/@zenfs/streams/dist/events.d.ts:44

EventKey

Listener[]

fs.WriteStream.listeners

Writable.listeners


off(type, listener): this

Defined in: node_modules/@zenfs/streams/dist/events.d.ts:42

EventKey

Listener

this

fs.WriteStream.off

Writable.off


on(type, listener): this

Defined in: node_modules/@zenfs/streams/dist/events.d.ts:37

EventKey

Listener

this

fs.WriteStream.on

Writable.on


once(type, listener): this

Defined in: node_modules/@zenfs/streams/dist/events.d.ts:39

EventKey

Listener

this

fs.WriteStream.once

Writable.once


pipe<T>(dest): T

Defined in: node_modules/@zenfs/streams/dist/writable.d.ts:132

Writables are not readable, so piping from one is always an error.

T extends PipeDestination

T

T

fs.WriteStream.pipe

Writable.pipe


prependListener(type, listener): this

Defined in: node_modules/@zenfs/streams/dist/events.d.ts:38

EventKey

Listener

this

fs.WriteStream.prependListener

Writable.prependListener


prependOnceListener(type, listener): this

Defined in: node_modules/@zenfs/streams/dist/events.d.ts:40

EventKey

Listener

this

fs.WriteStream.prependOnceListener

Writable.prependOnceListener


rawListeners(type): Listener[]

Defined in: node_modules/@zenfs/streams/dist/events.d.ts:45

EventKey

Listener[]

fs.WriteStream.rawListeners

Writable.rawListeners


removeAllListeners(type?): this

Defined in: node_modules/@zenfs/streams/dist/events.d.ts:43

EventKey

this

fs.WriteStream.removeAllListeners

Writable.removeAllListeners


removeListener(type, listener): this

Defined in: node_modules/@zenfs/streams/dist/events.d.ts:41

EventKey

Listener

this

fs.WriteStream.removeListener

Writable.removeListener


setDefaultEncoding(encoding): this

Defined in: node_modules/@zenfs/streams/dist/writable.d.ts:138

The writable.setDefaultEncoding() method sets the default encoding for a Writable stream.

BufferEncoding

The new default encoding

this

v0.11.15

fs.WriteStream.setDefaultEncoding

Writable.setDefaultEncoding


setMaxListeners(n): this

Defined in: node_modules/@zenfs/streams/dist/events.d.ts:33

number

this

fs.WriteStream.setMaxListeners

Writable.setMaxListeners


uncork(): void

Defined in: node_modules/@zenfs/streams/dist/writable.d.ts:137

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, 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());

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().

void

v0.11.2

fs.WriteStream.uncork

Writable.uncork


write(chunk, encoding?, callback?): boolean

Defined in: node_modules/@zenfs/streams/dist/writable.d.ts:133

The writable.write() method writes some data to the stream, and calls the supplied callback once the data has been fully handled. If an error occurs, the callback will be called with the error as its first argument. The callback is called asynchronously and before 'error' is emitted.

The return value is true if the internal buffer is less than the highWaterMark configured when the stream was created after admitting chunk. If false is returned, further attempts to write data to the stream should stop until the 'drain' event is emitted.

While a stream is not draining, calls to write() will buffer chunk, and return false. Once all currently buffered chunks are drained (accepted for delivery by the operating system), the 'drain' event will be emitted. Once write() returns false, do not write more chunks until the 'drain' event is emitted. While calling write() on a stream that is not draining is allowed, Node.js will buffer all written chunks until maximum memory usage occurs, at which point it will abort unconditionally. Even before it aborts, high memory usage will cause poor garbage collector performance and high RSS (which is not typically released back to the system, even after the memory is no longer required). Since TCP sockets may never drain if the remote peer does not read the data, writing a socket that is not draining may lead to a remotely exploitable vulnerability.

Writing data while the stream is not draining is particularly problematic for a Transform, because the Transform streams are paused by default until they are piped or a 'data' or 'readable' event handler is added.

If the data to be written can be generated or fetched on demand, it is recommended to encapsulate the logic into a Readable and use pipe. However, if calling write() is preferred, it is possible to respect backpressure and avoid memory issues using the 'drain' event:

function write(data, cb) {
if (!stream.write(data)) {
stream.once('drain', cb);
} else {
process.nextTick(cb);
}
}
// Wait for cb to be called before doing any other write.
write('hello', () => {
console.log('Write completed, do more writes now.');
});

A Writable stream in object mode will always ignore the encoding argument.

any

Optional data to write. For streams not operating in object mode, chunk must be a {string}, {Buffer}, {TypedArray} or {DataView}. For object mode streams, chunk may be any JavaScript value other than null.

BufferEncoding | null

Callback

Callback for when this chunk of data is flushed.

boolean

false if the stream wishes for the calling code to wait for the 'drain' event to be emitted before continuing to write additional data; otherwise true.

v0.9.4

fs.WriteStream.write

Writable.write

write(chunk, callback?): boolean

Defined in: node_modules/@zenfs/streams/dist/writable.d.ts:134

Writes data to the stream, with an explicit encoding for string data.

any

Optional data to write. For streams not operating in object mode, chunk must be a {string}, {Buffer}, {TypedArray} or {DataView}. For object mode streams, chunk may be any JavaScript value other than null.

Callback

Callback for when this chunk of data is flushed.

boolean

false if the stream wishes for the calling code to wait for the 'drain' event to be emitted before continuing to write additional data; otherwise true.

Writable.write for full details.

v0.9.4

fs.WriteStream.write

Writable.write


static [hasInstance](instance): boolean

Defined in: node_modules/@zenfs/streams/dist/writable.d.ts:130

Recognizes a Duplex, which inherits from Readable and so is not a structural subclass.

unknown

boolean

Writable.[hasInstance]


static fromWeb(writableStream, options?): Writable

Defined in: node_modules/@zenfs/streams/dist/writable.d.ts:165

Wraps a WHATWG WritableStream.

WritableStream

WritableOptions<Writable>

Writable

Writable.fromWeb


static toWeb(streamWritable): WritableStream

Defined in: node_modules/@zenfs/streams/dist/writable.d.ts:167

Exposes this stream as a WHATWG WritableStream.

Writable

WritableStream

Writable.toWeb