Class PreloadFile<FS>

An implementation of the File interface that operates on a file that is completely in-memory. PreloadFiles are backed by a Uint8Array.

Type Parameters

Hierarchy (view full)

Constructors

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

    Type Parameters

    Parameters

    • fs: FS

      The file system that created the file.

    • path: string

      Path to the file

    • flag: string
    • stats: Stats

      The stats object for the given file. PreloadFile will mutate this object. Note that this object must contain the appropriate mode that the file was opened as.

    • _buffer: Uint8Array = ...

    Returns PreloadFile<FS>

Properties

_buffer: Uint8Array = ...
_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
fs: FS

The file system that created the file.

path: string

Path to the file

stats: Stats

The stats object for the given file. PreloadFile will mutate this object. Note that this object must contain the appropriate mode that the file was opened as.

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(newPos): void
  • Set the file position.

    Parameters

    • newPos: number

      new position

    Returns void

Methods

  • Parameters

    • buffer: ArrayBufferView
    • offset: number = 0
    • length: number = ...
    • Optional position: number

    Returns number

  • Parameters

    • length: number

    Returns void

  • Parameters

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

    Returns number

  • Asynchronous fchmod.

    Parameters

    • mode: number

      the mode

    Returns Promise<void>

  • Asynchronous fchown.

    Parameters

    • uid: number
    • gid: number

    Returns Promise<void>

  • Asynchronous datasync.

    Default implementation maps to sync.

    Returns Promise<void>

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

    Parameters

    • Optional force: 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.

    • Optional offset: number

      The offset within the buffer where writing will start.

    • Optional length: number

      An integer specifying the number of bytes to read.

    • Optional position: 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.

    • Optional offset: number

      The offset within the buffer where writing will start.

    • Optional length: number

      An integer specifying the number of bytes to read.

    • Optional position: 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

  • Asynchronous truncate.

    Parameters

    • length: number

    Returns Promise<void>

  • 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. Note that it is unsafe to use fs.write multiple times on the same file without waiting for the callback.

    Parameters

    • buffer: Uint8Array

      Uint8Array containing the data to write to the file.

    • Optional offset: number

      Offset in the buffer to start reading data from.

    • Optional length: number

      The amount of bytes to write to the file.

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

  • Write buffer to the file. Note that it is unsafe to use fs.writeSync multiple times on the same file without waiting for the callback.

    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