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

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

Link copied to clipboard
val closeEvent: EventInstance<ERROR CLASS: Symbol not found for js.array.Tuple>
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
val drainEvent: EventInstance<ERROR CLASS: Symbol not found for js.array.Tuple>
Link copied to clipboard
val dropEvent: EventInstance<ERROR CLASS: Symbol not found for js.array.Tuple1<kotlin/Any>>
Link copied to clipboard
val errorEvent: EventInstance<ERROR CLASS: Symbol not found for js.array.Tuple1<ERROR CLASS: Symbol not found for js.errors.JsError>>
Link copied to clipboard
val fd: Double

The file descriptor that is being written to.

Link copied to clipboard

The file that is being written to.

Link copied to clipboard
val finishEvent: EventInstance<ERROR CLASS: Symbol not found for js.array.Tuple>
Link copied to clipboard

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

Link copied to clipboard

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

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

Link copied to clipboard

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
val mode: Any

The mode of the file that is being written to.

Link copied to clipboard

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

Link copied to clipboard
val readyEvent: EventInstance<ERROR CLASS: Symbol not found for js.array.Tuple>
Link copied to clipboard

Whether the stream is writing synchronously or asynchronously.

Link copied to clipboard
val writeEvent: EventInstance<ERROR CLASS: Symbol not found for js.array.Tuple1<kotlin/Double>>
Link copied to clipboard

Whether the stream is currently writing data to the file.

Functions

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

Alias for emitter.on(eventName, listener).

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

events.EventEmitter

Link copied to clipboard
fun destroy()

Close the stream immediately, without flushing the internal buffer.

Link copied to clipboard
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
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
fun flush(callback: (@R|kotlin/ParameterName|(name = String(err)) ERROR CLASS: Symbol not found for js.errors.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
fun flushSync()

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

Link copied to clipboard

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
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
fun off(type: EventType, listener: EventListener)

Alias for emitter.removeListener().

Link copied to clipboard
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.

fun on(event: String, listener: Function<Unit>)
Link copied to clipboard
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.

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

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.

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

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.

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
fun removeAllListeners(type: EventType = definedExternally)

Removes all listeners, or those of the specified eventName.

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

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

Link copied to clipboard
fun reopen(file: PathLike)

Reopen the file in place, useful for log rotation.

Link copied to clipboard

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
fun write(data: String): Boolean
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.