Options
All
  • Public
  • Public/Protected
  • All
Menu

Hierarchy

  • FileHandle

Index

Properties

fd

fd: number

Gets the file descriptor for this file handle.

Methods

appendFile

  • 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

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

    • Optional options: BaseEncodingOptions & object | BufferEncoding | null

      Either the encoding for the file, or an object optionally specifying the encoding, file mode, and flag. If encoding is not supplied, the default of 'utf8' is used. If mode is not supplied, the default of 0o666 is used. If mode is a string, it is parsed as an octal integer. If flag is not supplied, the default of 'a' is used.

    Returns Promise<void>

chmod

  • chmod(mode: Mode): 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>

chown

  • chown(uid: number, gid: number): Promise<void>
  • Asynchronous fchown(2) - Change ownership of a file.

    Parameters

    • uid: number
    • gid: number

    Returns Promise<void>

close

  • close(): Promise<void>
  • Asynchronous close(2) - close a FileHandle.

    Returns Promise<void>

datasync

  • datasync(): Promise<void>
  • Asynchronous fdatasync(2) - synchronize a file's in-core state with storage device.

    Returns Promise<void>

read

  • read<TBuffer>(buffer: TBuffer, offset?: number | null, length?: number | null, position?: number | null): Promise<object>
  • Asynchronously reads data from the file. The FileHandle must have been opened for reading.

    Type parameters

    • TBuffer: Uint8Array

    Parameters

    • buffer: TBuffer

      The buffer that the data will be written to.

    • Optional offset: number | null

      The offset in the buffer at which to start writing.

    • Optional length: number | null

      The number of bytes to read.

    • Optional position: number | null

      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<object>

readFile

  • 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: object | null

      An object that may contain an optional flag. If a flag is not provided, it defaults to 'r'.

    Returns Promise<Buffer>

  • 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: object | BufferEncoding

      An object that may contain an optional flag. If a flag is not provided, it defaults to 'r'.

    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

    Returns Promise<string | Buffer>

readv

  • See fs.readv promisified version.

    Parameters

    Returns Promise<ReadVResult>

stat

  • Asynchronous fstat(2) - Get file status.

    Parameters

    Returns Promise<Stats>

  • Parameters

    Returns Promise<BigIntStats>

  • Parameters

    Returns Promise<Stats | BigIntStats>

sync

  • sync(): Promise<void>
  • Asynchronous fsync(2) - synchronize a file's in-core state with the underlying storage device.

    Returns Promise<void>

truncate

  • truncate(len?: number): Promise<void>
  • Asynchronous ftruncate(2) - Truncate a file to a specified length.

    Parameters

    • Optional len: number

      If not specified, defaults to 0.

    Returns Promise<void>

utimes

  • utimes(atime: string | number | Date, mtime: string | number | Date): 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>

write

  • write<TBuffer>(buffer: TBuffer, offset?: number | null, length?: number | null, position?: number | null): Promise<object>
  • write(data: string | Uint8Array, position?: number | null, encoding?: BufferEncoding | null): Promise<object>
  • Asynchronously writes buffer to the file. The FileHandle must have been opened for writing.

    Type parameters

    • TBuffer: Uint8Array

    Parameters

    • buffer: TBuffer

      The buffer that the data will be written to.

    • Optional offset: number | null

      The part of the buffer to be written. If not supplied, defaults to 0.

    • Optional length: number | null

      The number of bytes to write. If not supplied, defaults to buffer.length - offset.

    • Optional position: number | null

      The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.

    Returns Promise<object>

  • 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, fs.createWriteStream is strongly recommended.

    Parameters

    • data: string | Uint8Array
    • Optional position: number | null

      The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.

    • Optional encoding: BufferEncoding | null

      The expected string encoding.

    Returns Promise<object>

writeFile

  • 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

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

    • Optional options: BaseEncodingOptions & object | BufferEncoding | null

      Either the encoding for the file, or an object optionally specifying the encoding, file mode, and flag. If encoding is not supplied, the default of 'utf8' is used. If mode is not supplied, the default of 0o666 is used. If mode is a string, it is parsed as an octal integer. If flag is not supplied, the default of 'w' is used.

    Returns Promise<void>

writev

  • See fs.writev promisified version.

    Parameters

    Returns Promise<WriteVResult>

Generated using TypeDoc