Utf8Stream

external class Utf8Stream : EventEmitter(source)

An optimized UTF-8 stream writer that allows for flushing all the internal buffering on demand. It handles EAGAIN errors correctly, allowing for customization, for example, by dropping content if the disk is busy.

Since

v24.6.0

Constructors

Link copied to clipboard
constructor(options: Utf8StreamOptions)

Properties

Link copied to clipboard
external val append: Boolean

Whether the stream is appending to the file or truncating it.

Link copied to clipboard
Link copied to clipboard

The type of data that can be written to the stream. Supported values are 'utf8' or 'buffer'.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
external val fd: Double

The file descriptor that is being written to.

Link copied to clipboard
external val file: String

The file that is being written to.

Link copied to clipboard
Link copied to clipboard
external val fsync: Boolean

Whether the stream is performing a fs.fsyncSync() after every write operation.

Link copied to clipboard
external val maxLength: Double

The maximum length of the internal buffer. If a write operation would cause the buffer to exceed maxLength, the data written is dropped and a drop event is emitted with the dropped data.

Link copied to clipboard
external val minLength: Double

The minimum length of the internal buffer that is required to be full before flushing.

Link copied to clipboard
external val mkdir: Boolean

Whether the stream should ensure that the directory for the dest file exists. If true, it will create the directory if it does not exist.

Link copied to clipboard
external val mode: Any

The mode of the file that is being written to.

Link copied to clipboard
external val periodicFlush: Double

The number of milliseconds between flushes. If set to 0, no periodic flushes will be performed.

Link copied to clipboard
Link copied to clipboard
external val sync: Boolean

Whether the stream is writing synchronously or asynchronously.

Link copied to clipboard
Link copied to clipboard
external val writing: Boolean

Whether the stream is currently writing data to the file.

Functions

Link copied to clipboard
external fun addListener(type: EventType, listener: EventListener)

Alias for emitter.on(eventName, listener).

external fun addListener(event: String, listener: Function<Unit>)

events.EventEmitter

Link copied to clipboard
external fun destroy()

Close the stream immediately, without flushing the internal buffer.

Link copied to clipboard
external fun emit(type: EventType, vararg args: Any?): Boolean

Synchronously calls each of the listeners registered for the event named eventName, in the order they were registered, passing the supplied arguments to each.

Link copied to clipboard
external fun end()

Close the stream gracefully, flushing the internal buffer before closing.

Link copied to clipboard

Returns an array listing the events for which the emitter has registered listeners. The values in the array are strings or Symbols.

Link copied to clipboard
external fun flush(callback: (JsError?) -> Unit)

Writes the current buffer to the file if a write was not in progress. Do nothing if minLength is zero or if it is already writing.

Link copied to clipboard
external fun flushSync()

Flushes the buffered data synchronously. This is a costly operation.

Link copied to clipboard
external fun getMaxListeners(): Double

Returns the current max listener value for the EventEmitter which is either set by emitter.setMaxListeners(n) or defaults to {@link EventEmitter.defaultMaxListeners}.

Link copied to clipboard
external fun listenerCount(type: EventType, listener: EventListener = definedExternally): Double

Returns the number of listeners listening for the event named eventName. If listener is provided, it will return how many times the listener is found in the list of the listeners of the event.

Link copied to clipboard

Returns a copy of the array of listeners for the event named eventName.

Link copied to clipboard
external fun off(type: EventType, listener: EventListener)

Alias for emitter.removeListener().

Link copied to clipboard
external fun on(type: EventType, listener: EventListener)

Adds the listener function to the end of the listeners array for the event named eventName. No checks are made to see if the listener has already been added. Multiple calls passing the same combination of eventName and listener will result in the listener being added, and called, multiple times.

external fun on(event: String, listener: Function<Unit>)
Link copied to clipboard
external fun once(type: EventType, listener: EventListener)

Adds a one-time listener function for the event named eventName. The next time eventName is triggered, this listener is removed and then invoked.

external fun once(event: String, listener: Function<Unit>)
Link copied to clipboard
external fun prependListener(type: EventType, listener: EventListener)

Adds the listener function to the beginning of the listeners array for the event named eventName. No checks are made to see if the listener has already been added. Multiple calls passing the same combination of eventName and listener will result in the listener being added, and called, multiple times.

external fun prependListener(event: String, listener: Function<Unit>)
Link copied to clipboard
external fun prependOnceListener(type: EventType, listener: EventListener)

Adds a one-timelistener function for the event named eventName to the beginning of the listeners array. The next time eventName is triggered, this listener is removed, and then invoked.

external fun prependOnceListener(event: String, listener: Function<Unit>)
Link copied to clipboard

Returns a copy of the array of listeners for the event named eventName, including any wrappers (such as those created by .once()).

Link copied to clipboard
external fun removeAllListeners(type: EventType = definedExternally)

Removes all listeners, or those of the specified eventName.

Link copied to clipboard
external fun removeListener(type: EventType, listener: EventListener)

Removes the specified listener from the listener array for the event named eventName.

Link copied to clipboard
external fun reopen(file: PathLike)

Reopen the file in place, useful for log rotation.

Link copied to clipboard
external fun setMaxListeners(n: Number)

By default EventEmitters will print a warning if more than 10 listeners are added for a particular event. This is a useful default that helps finding memory leaks. The emitter.setMaxListeners() method allows the limit to be modified for this specific EventEmitter instance. The value can be set to Infinity (or 0) to indicate an unlimited number of listeners.

Link copied to clipboard
external fun write(data: String): Boolean
external fun write(data: Buffer<*>): Boolean

When the options.contentMode is set to 'utf8' when the stream is created, the data argument must be a string. If the contentMode is set to 'buffer', the data argument must be a Buffer.