Options
All
  • Public
  • Public/Protected
  • All
Menu

Filesystem IO

These are designed to match nodejs fs module.

DO NOT use IO for savedata. Please use DB namespace so your data can be managed by WebUI.

Also, due to difference between operating systems, you should always prepare your files using ascii path. Both UTF-8 and local encodings will have cross-platform compatibility issues.

Index

Functions

  • Exists(path: string): boolean
  • Synchronously tests whether or not the given path exists by checking with the file system.

    Parameters

    • path: string

      A path to a file or directory. If a URL is provided, it must use the file: protocol. URL support is experimental.

    Returns boolean

  • ReadDir(path: string): Promise<{ name: string; type: "file" | "dir" | "unsupported" }[]>
  • Asynchronously read a directory.

    Parameters

    • path: string

      A path to a directory.

    Returns Promise<{ name: string; type: "file" | "dir" | "unsupported" }[]>

  • ReadFile(path: string, options: { encoding?: null; flag?: string }): Promise<Buffer | null>
  • ReadFile(path: string, options: string | { encoding: string; flag?: string }): Promise<string | null>
  • ReadFile(path: string, options: string | { encoding?: string; flag?: string }): Promise<string | Buffer | null>
  • ReadFile(path: string): Promise<Buffer | null>
  • Asynchronously reads the entire contents of a file.

    Parameters

    • path: string

      A path to a file. If a file descriptor is provided, the underlying file will not be closed automatically.

    • options: { encoding?: null; flag?: string }

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

      Returns null if any error occurs while reading a file

      • Optional encoding?: null
      • Optional flag?: string

    Returns Promise<Buffer | null>

  • Asynchronously reads the entire contents of a file.

    Parameters

    • path: string

      A path to a file. If a file descriptor is provided, the underlying file will not be closed automatically.

    • options: string | { encoding: string; flag?: string }

      Either the encoding for the result, or an object that contains the encoding and an optional flag. If a flag is not provided, it defaults to 'r'.

      Returns null if any error occurs while reading a file

    Returns Promise<string | null>

  • Asynchronously reads the entire contents of a file.

    Parameters

    • path: string

      A path to a file. If a file descriptor is provided, the underlying file will not be closed automatically.

    • options: string | { encoding?: string; flag?: string }

      Either the encoding for the result, or an object that contains the encoding and an optional flag. If a flag is not provided, it defaults to 'r'.

      Returns null if any error occurs while reading a file

    Returns Promise<string | Buffer | null>

  • Asynchronously reads the entire contents of a file.

    Parameters

    • path: string

      A path to a file. If a file descriptor is provided, the underlying file will not be closed automatically.

      Returns null if any error occurs while reading a file.

    Returns Promise<Buffer | null>

  • Resolve(path: string): string
  • Resolve a relative path starting from your plugin directory to an absolute path.

    Parameters

    • path: string

    Returns string

  • WriteFile(path: string, data: any, options: string | { encoding?: string; flag?: string; mode?: string | number }): Promise<void>
  • WriteFile(path: string, data: any): Promise<void>
  • Asynchronously writes data to a file, replacing the file if it already exists.

    Parameters

    • path: string

      A path to a file. If a file descriptor is provided, the underlying file will not be closed automatically.

    • data: any

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

    • options: string | { encoding?: string; flag?: string; mode?: string | number }

      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>

  • Asynchronously writes data to a file, replacing the file if it already exists.

    Parameters

    • path: string

      A path to a file. If a file descriptor is provided, the underlying file will not be closed automatically.

    • data: any

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

    Returns Promise<void>

Generated using TypeDoc