Class PreloadFile<FS>

An implementation of File that operates completely in-memory. PreloadFiles are backed by a Uint8Array.

Type Parameters

Hierarchy (view full)

Constructors

  • Creates a file with path and, optionally, the given contents. Note that, if contents is specified, it will be mutated by the file.

    Type Parameters

    Parameters

    • fs: FS
    • path: string
    • flag: string
    • stats: Stats
    • _buffer: Uint8Array = ...

      A buffer containing the entire contents of the file.

    Returns PreloadFile<FS>

Properties

_buffer: Uint8Array = ...

A buffer containing the entire contents of the file.

_position: number = 0

Current position

closed: boolean = false

Whether the file is open or closed

dirty: boolean = false

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

flag: string

The file system that created the file

path: string
stats: Stats

Accessors

  • get buffer(): Uint8Array
  • Get the underlying buffer for this file. Mutating not recommended and will mess up dirty tracking.

    Returns Uint8Array

  • 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): void
  • Get the current file position.

    Parameters

    • value: number

    Returns void

Methods

  • Parameters

    • buffer: ArrayBufferView
    • offset: number = 0
    • length: number = ...
    • Optionalposition: number

    Returns number

  • Parameters

    • length: number

    Returns void

  • Parameters

    • buffer: Uint8Array
    • offset: number = 0
    • length: number = ...
    • position: number = ...

    Returns number

  • Parameters

    • uid: number
    • gid: number

    Returns Promise<void>

  • Default implementation maps to sync.

    Returns Promise<void>

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

    Parameters

    • Optionalforce: boolean

    Returns void

  • Read data from the file.

    Type Parameters

    • TBuffer extends ArrayBufferView

    Parameters

    • buffer: TBuffer

      The buffer that the data will be written to.

    • Optionaloffset: number

      The offset within the buffer where writing will start.

    • Optionallength: number

      An integer specifying the number of bytes to read.

    • Optionalposition: number

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

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

  • Read data from the file.

    Parameters

    • buffer: ArrayBufferView

      The buffer that the data will be written to.

    • Optionaloffset: number

      The offset within the buffer where writing will start.

    • Optionallength: number

      An integer specifying the number of bytes to read.

    • Optionalposition: number

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

    Returns number

    number of bytes written

  • Change the file timestamps of the file.

    Parameters

    • atime: Date
    • mtime: Date

    Returns Promise<void>

  • Change the file timestamps of the file.

    Parameters

    • atime: Date
    • mtime: Date

    Returns void

  • Write buffer to the file.

    Parameters

    • buffer: Uint8Array

      Uint8Array containing the data to write to the file.

    • Optionaloffset: number

      Offset in the buffer to start reading data from.

    • Optionallength: number

      The amount of bytes to write to the file.

    • Optionalposition: 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>

  • 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 number

    bytes written