ZenFS
    Preparing search index...

    Class FileHandle

    Implements

    • FileHandle
    Index

    Constructors

    Properties

    _buffer?: Uint8Array<ArrayBufferLike>
    _position: number = 0

    Current position

    closed: boolean = false

    Whether the file is open or closed

    context: V_Context
    dirty: boolean = false

    Whether the file has changes which have not been written to the FS

    fd: number
    flag: number

    The flag the handle was opened with

    The internal FS associated with the handle

    inode: InodeLike

    Stats for the handle

    internalPath: string

    The path relative to the FileSystem's root

    path: string

    The path relative to the context's root

    Accessors

    • get position(): number

      Get the current file position.

      We emulate the following bug mentioned in the Node documentation:

      On Linux, positional writes don't work when the file is opened in append mode. The kernel ignores the position argument and always appends the data to the end of the file.

      Returns number

      The current file position.

    • set position(value: number): void

      Parameters

      • value: number

      Returns void

    Methods

    • Read data from the file.

      Type Parameters

      • TBuffer extends ArrayBufferView<ArrayBufferLike>

      Parameters

      • buffer: TBuffer

        The buffer that the data will be written to.

      • offset: number = 0

        The offset within the buffer where writing will start.

      • length: number = ...

        An integer specifying the number of bytes to read.

      • position: number = ...

        An integer specifying where to begin reading from in the file. If position is unset, data will be read from the current file position.

      Returns Promise<{ buffer: TBuffer; bytesRead: number }>

    • Write buffer to the file.

      Parameters

      • buffer: Uint8Array

        Uint8Array containing the data to write to the file.

      • offset: number = 0

        Offset in the buffer to start reading data from.

      • length: number = ...

        The amount of bytes to write to the file.

      • position: number = ...

        Offset from the beginning of the file where this data should be written. If position is null, the data will be written at the current position.

      Returns Promise<number>

    • Returns Promise<void>

    • Asynchronously append data to a file, creating the file if it does not exist. The underlying file will not be closed automatically. The FileHandle must have been opened for appending.

      Parameters

      • data: string | Uint8Array<ArrayBufferLike>

        The data to write. If something other than a Buffer or Uint8Array is provided, the value is coerced to a string.

      • _options: BufferEncoding | ObjectEncodingOptions & FlagAndOpenMode = {}

        Either the encoding for the file, or an object optionally specifying the encoding, file mode, and flag.

        • encoding defaults to 'utf8'.
        • mode defaults to 0o666.
        • flag defaults to 'a'.

      Returns Promise<void>

    • Asynchronous fchmod(2) - Change permissions of a file.

      Parameters

      • mode: Mode

        A file mode. If a string is passed, it is parsed as an octal integer.

      Returns Promise<void>

    • Asynchronous fchown(2) - Change ownership of a file.

      Parameters

      • uid: number
      • gid: number

      Returns Promise<void>

    • Asynchronous close(2) - close a FileHandle.

      Returns Promise<void>

    • Creates a stream for reading from the file.

      Parameters

      • options: CreateReadStreamOptions = {}

        Options for the readable stream

      Returns ReadStream

    • Creates a stream for writing to the file.

      Parameters

      • options: CreateWriteStreamOptions = {}

        Options for the writeable stream.

      Returns WriteStream

    • Asynchronous fdatasync(2) - synchronize a file's in-core state with storage device.

      Returns Promise<void>

    • Cleans up. This will not sync the file data to the FS

      Parameters

      • Optionalforce: boolean

      Returns void

    • Asynchronously reads data from the file. The FileHandle must have been opened for reading.

      Type Parameters

      • T extends ArrayBufferView<ArrayBufferLike>

      Parameters

      • buffer: T

        The buffer that the data will be written to.

      • Optionaloffset: number

        The offset in the buffer at which to start writing.

      • Optionallength: number

        The number of bytes to read.

      • Optionalposition: null | number

        The offset from the beginning of the file from which data should be read. If null, data will be read from the current position.

      Returns Promise<FileReadResult<T>>

    • Asynchronously reads data from the file. The FileHandle must have been opened for reading.

      Type Parameters

      • T extends ArrayBufferView<ArrayBufferLike> = Buffer<ArrayBufferLike>

      Parameters

      • buffer: T

        The buffer that the data will be written to.

      • Optionaloptions: FileReadOptions<T>

      Returns Promise<FileReadResult<T>>

    • Asynchronously reads data from the file. The FileHandle must have been opened for reading.

      Type Parameters

      • T extends ArrayBufferView<ArrayBufferLike> = Buffer<ArrayBufferLike>

      Parameters

      • Optionaloptions: FileReadOptions<T>

      Returns Promise<FileReadResult<T>>

    • Read file data using a ReadableStream. The handle will not be closed automatically.

      Parameters

      Returns ReadableStream<Uint8Array<ArrayBufferLike>>

    • Asynchronously reads the entire contents of a file.

      If options is a string, then it specifies the encoding.

      The FileHandle has to support reading.

      If one or more filehandle.read() calls are made on a file handle and then a filehandle.readFile() call is made, the data will be read from the current position till the end of the file. It doesn't always read from the beginning of the file.

      Parameters

      • Optionaloptions: null | { encoding?: null } & Abortable

      Returns Promise<Buffer<ArrayBufferLike>>

      Fulfills upon a successful read with the contents of the file. If no encoding is specified (using options.encoding), the data is returned as a {Buffer} object. Otherwise, the data will be a string.

      v10.0.0

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

      Parameters

      • options: BufferEncoding | { encoding: BufferEncoding } & Abortable

      Returns Promise<string>

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

      Parameters

      • Optional_options: null | BufferEncoding | ObjectEncodingOptions & Abortable

      Returns Promise<string | Buffer<ArrayBufferLike>>

    • Creates a readline Interface object that allows reading the file line by line

      Parameters

      • Optionaloptions: CreateReadStreamOptions

        Options for creating a read stream

      Returns Interface

      A readline interface for reading the file line by line

    • Asynchronous readv. Reads into multiple buffers.

      Parameters

      • buffers: ArrayBufferView<ArrayBufferLike>[]

        An array of Uint8Array buffers.

      • Optionalposition: number

        The position in the file where to begin reading.

      Returns Promise<ReadVResult>

      The number of bytes read.

    • Asynchronous fstat(2) - Get file status.

      Parameters

      • opts: BigIntOptions

      Returns Promise<BigIntStats>

    • Asynchronous fstat(2) - Get file status.

      Parameters

      • Optionalopts: StatOptions & { bigint?: false }

      Returns Promise<Stats>

    • Asynchronous fsync(2) - synchronize a file's in-core state with the underlying storage device.

      Returns Promise<void>

    • Asynchronous ftruncate(2) - Truncate a file to a specified length.

      Parameters

      • length: number = 0

        If not specified, defaults to 0.

      Returns Promise<void>

    • Asynchronously change file timestamps of the file.

      Parameters

      • atime: string | number | Date

        The last access time. If a string is provided, it will be coerced to number.

      • mtime: string | number | Date

        The last modified time. If a string is provided, it will be coerced to number.

      Returns Promise<void>

    • Internal

      Not part of the Node.js API!

      Write file data using a WritableStream. The handle will not be closed automatically.

      Parameters

      Returns WritableStream

    • Asynchronously writes string to the file. The FileHandle must have been opened for writing. It is unsafe to call write() multiple times on the same file without waiting for the Promise to be resolved (or rejected). For this scenario, createWriteStream is strongly recommended.

      Type Parameters

      • T extends FileContents

      Parameters

      • data: T
      • Optionaloptions: null | number | { length?: number; offset?: number; position?: number }
      • OptionallenOrEnc: null | number | BufferEncoding
      • Optionalposition: null | number

      Returns Promise<{ buffer: T; bytesWritten: number }>

    • Asynchronously writes data to a file, replacing the file if it already exists. The underlying file will not be closed automatically. The FileHandle must have been opened for writing. It is unsafe to call writeFile() multiple times on the same file without waiting for the Promise to be resolved (or rejected).

      Parameters

      • data: string | Uint8Array<ArrayBufferLike>

        The data to write. If something other than a Buffer or Uint8Array is provided, the value is coerced to a string.

      • _options: WriteFileOptions = {}

        Either the encoding for the file, or an object optionally specifying the encoding, file mode, and flag.

        • encoding defaults to 'utf8'.
        • mode defaults to 0o666.
        • flag defaults to 'w'.

      Returns Promise<void>

    • Asynchronous writev. Writes from multiple buffers.

      Parameters

      • buffers: Uint8Array<ArrayBufferLike>[]

        An array of Uint8Array buffers.

      • Optionalposition: number

        The position in the file where to begin writing.

      Returns Promise<WriteVResult>

      The number of bytes written.