FileHandle

sealed external interface FileHandle(source)

Properties

Link copied to clipboard
abstract val fd: Double

The numeric file descriptor managed by the {FileHandle} object.

Functions

Link copied to clipboard
abstract suspend fun appendFile(data: Uint8Array<*>): Void
abstract suspend fun appendFile(data: Uint8Array<*>, options: BufferEncoding? = definedExternally): Void
abstract suspend fun appendFile(data: Uint8Array<*>, options: FileHandleAppendFileAsyncOptions? = definedExternally): Void
abstract suspend fun appendFile(data: String, options: BufferEncoding? = definedExternally): Void
abstract suspend fun appendFile(data: String, options: FileHandleAppendFileAsyncOptions? = definedExternally): Void

Alias of filehandle.writeFile().

abstract suspend fun appendFile(data: String): Void
Link copied to clipboard
abstract fun appendFileAsync(data: Uint8Array<*>): Promise<Void>
abstract fun appendFileAsync(data: String): Promise<Void>
abstract fun appendFileAsync(data: Uint8Array<*>, options: BufferEncoding? = definedExternally): Promise<Void>
abstract fun appendFileAsync(data: Uint8Array<*>, options: FileHandleAppendFileAsyncOptions? = definedExternally): Promise<Void>
abstract fun appendFileAsync(data: String, options: BufferEncoding? = definedExternally): Promise<Void>
abstract fun appendFileAsync(data: String, options: FileHandleAppendFileAsyncOptions? = definedExternally): Promise<Void>

Alias of filehandle.writeFile().

Link copied to clipboard
abstract suspend fun chmod(mode: Mode): Void
Link copied to clipboard
abstract fun chmodAsync(mode: Mode): Promise<Void>

Modifies the permissions on the file. See chmod(2).

Link copied to clipboard
abstract suspend fun chown(uid: Number, gid: Number): Void
Link copied to clipboard
abstract fun chownAsync(uid: Number, gid: Number): Promise<Void>

Changes the ownership of the file. A wrapper for chown(2).

Link copied to clipboard
abstract suspend fun close(): Void
Link copied to clipboard
abstract fun closeAsync(): Promise<Void>

Closes the file handle after waiting for any pending operation on the handle to complete.

Link copied to clipboard
abstract fun createReadStream(options: CreateReadStreamOptions = definedExternally): ReadStream

Unlike the 16 KiB default highWaterMark for a stream.Readable, the stream returned by this method has a default highWaterMark of 64 KiB.

Link copied to clipboard
abstract fun createWriteStream(options: CreateWriteStreamOptions = definedExternally): WriteStream

options may also include a start option to allow writing data at some position past the beginning of the file, allowed values are in the \[0, Number.MAX_SAFE_INTEGER\] range. Modifying a file rather than replacing it may require the flags open option to be set to r+ rather than the default r. The encoding can be any one of those accepted by Buffer.

Link copied to clipboard
abstract suspend fun datasync(): Void
Link copied to clipboard
abstract fun datasyncAsync(): Promise<Void>

Forces all currently queued I/O operations associated with the file to the operating system's synchronized I/O completion state. Refer to the POSIX fdatasync(2) documentation for details.

Link copied to clipboard
abstract suspend fun <T : ArrayBufferView<*>> read(options: FileReadOptions<T> = definedExternally): FileReadResult<T>
abstract suspend fun <T : ArrayBufferView<*>> read(buffer: T, offset: Double? = definedExternally, length: Double? = definedExternally, position: Double? = definedExternally): FileReadResult<T>
Link copied to clipboard
abstract fun readableWebStream(options: ReadableWebStreamOptions = definedExternally): ReadableStream<*>

Returns a ReadableStream that may be used to read the files data.

Link copied to clipboard
abstract fun <T : ArrayBufferView<*>> readAsync(options: FileReadOptions<T> = definedExternally): Promise<FileReadResult<T>>

abstract fun <T : ArrayBufferView<*>> readAsync(buffer: T, offset: Double? = definedExternally, length: Double? = definedExternally, position: Double? = definedExternally): Promise<FileReadResult<T>>

Reads data from the file and stores that in the given buffer.

Link copied to clipboard
abstract suspend fun readFile(): Any
abstract suspend fun readFile(options: FileHandleReadFileBufferAsyncOptions? = definedExternally): Buffer
abstract suspend fun readFile(options: FileHandleReadFileStringAsyncOptions): String

abstract suspend fun readFile(options: BufferEncoding): String
abstract suspend fun readFile(options: BufferEncoding? = definedExternally): Any
abstract suspend fun readFile(options: FileHandleReadFileAsyncOptions? = definedExternally): Any

Asynchronously reads the entire contents of a file. The underlying file will not be closed automatically. The FileHandle must have been opened for reading.

Link copied to clipboard
abstract fun readFileAsync(): Promise<Any>
abstract fun readFileAsync(options: BufferEncoding): Promise<String>
abstract fun readFileAsync(options: BufferEncoding? = definedExternally): Promise<Any>
abstract fun readFileAsync(options: FileHandleReadFileAsyncOptions? = definedExternally): Promise<Any>

Asynchronously reads the entire contents of a file. The underlying file will not be closed automatically. The FileHandle must have been opened for reading.

abstract fun readFileAsync(options: FileHandleReadFileBufferAsyncOptions? = definedExternally): Promise<Buffer>

Asynchronously reads the entire contents of a file.

Link copied to clipboard
abstract fun readLines(options: CreateReadStreamOptions = definedExternally): Interface

Convenience method to create a readline interface and stream over the file. See filehandle.createReadStream() for the options.

Link copied to clipboard
abstract suspend fun readv(buffers: ReadonlyArray<ArrayBufferView<*>>, position: Number = definedExternally): ReadVResult
Link copied to clipboard
abstract fun readvAsync(buffers: ReadonlyArray<ArrayBufferView<*>>, position: Number = definedExternally): Promise<ReadVResult>

Read from a file and write to an array of ArrayBufferView s

Link copied to clipboard
abstract suspend fun stat(opts: FileHandleStatBigIntOpts): BigIntStats
abstract suspend fun stat(opts: FileHandleStatOpts = definedExternally): Stats
abstract suspend fun stat(opts: StatOptions = definedExternally): Any
Link copied to clipboard
abstract fun statAsync(opts: FileHandleStatOpts = definedExternally): Promise<Stats>
abstract fun statAsync(opts: StatOptions = definedExternally): Promise<Any>
Link copied to clipboard
abstract suspend fun sync(): Void
Link copied to clipboard
abstract fun syncAsync(): Promise<Void>

Request that all data for the open file descriptor is flushed to the storage device. The specific implementation is operating system and device specific. Refer to the POSIX fsync(2) documentation for more detail.

Link copied to clipboard
abstract suspend fun truncate(len: Number = definedExternally): Void
Link copied to clipboard
abstract fun truncateAsync(len: Number = definedExternally): Promise<Void>

Truncates the file.

Link copied to clipboard
abstract suspend fun utimes(atime: TimeLike, mtime: TimeLike): Void
Link copied to clipboard
abstract fun utimesAsync(atime: TimeLike, mtime: TimeLike): Promise<Void>

Change the file system timestamps of the object referenced by the FileHandle then fulfills the promise with no arguments upon success.

Link copied to clipboard
abstract suspend fun write(data: String, position: Double? = definedExternally, encoding: BufferEncoding? = definedExternally): FileHandleWriteStringResultPayload
abstract suspend fun <TBuffer : Uint8Array<*>> write(buffer: TBuffer, offset: Double? = definedExternally, length: Double? = definedExternally, position: Double? = definedExternally): FileHandleWriteResultPayload<TBuffer>
Link copied to clipboard
abstract fun writeAsync(data: String, position: Double? = definedExternally, encoding: BufferEncoding? = definedExternally): Promise<FileHandleWriteStringResultPayload>

abstract fun <TBuffer : Uint8Array<*>> writeAsync(buffer: TBuffer, offset: Double? = definedExternally, length: Double? = definedExternally, position: Double? = definedExternally): Promise<FileHandleWriteResultPayload<TBuffer>>

Write buffer to the file.

Link copied to clipboard
abstract suspend fun writeFile(data: Uint8Array<*>): Void
abstract suspend fun writeFile(data: Uint8Array<*>, options: BufferEncoding? = definedExternally): Void
abstract suspend fun writeFile(data: Uint8Array<*>, options: FileHandleWriteFileAsyncOptions? = definedExternally): Void
abstract suspend fun writeFile(data: String, options: BufferEncoding? = definedExternally): Void
abstract suspend fun writeFile(data: String, options: FileHandleWriteFileAsyncOptions? = definedExternally): Void

Asynchronously writes data to a file, replacing the file if it already exists. data can be a string, a buffer, an AsyncIterable, or an Iterable object. The promise is fulfilled with no arguments upon success.

abstract suspend fun writeFile(data: String): Void
Link copied to clipboard
abstract fun writeFileAsync(data: Uint8Array<*>): Promise<Void>
abstract fun writeFileAsync(data: String): Promise<Void>
abstract fun writeFileAsync(data: Uint8Array<*>, options: BufferEncoding? = definedExternally): Promise<Void>
abstract fun writeFileAsync(data: Uint8Array<*>, options: FileHandleWriteFileAsyncOptions? = definedExternally): Promise<Void>
abstract fun writeFileAsync(data: String, options: BufferEncoding? = definedExternally): Promise<Void>
abstract fun writeFileAsync(data: String, options: FileHandleWriteFileAsyncOptions? = definedExternally): Promise<Void>

Asynchronously writes data to a file, replacing the file if it already exists. data can be a string, a buffer, an AsyncIterable, or an Iterable object. The promise is fulfilled with no arguments upon success.

Link copied to clipboard
abstract suspend fun writev(buffers: ReadonlyArray<ArrayBufferView<*>>, position: Number = definedExternally): WriteVResult
Link copied to clipboard
abstract fun writevAsync(buffers: ReadonlyArray<ArrayBufferView<*>>, position: Number = definedExternally): Promise<WriteVResult>

Write an array of ArrayBufferView s to the file.