Class PreloadFile<T>

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

This is also an abstract class, as it lacks an implementation of 'sync' and 'close'. Each filesystem that wishes to use this file representation must extend this class and implement those two methods.

Todo

'close' lever that disables functionality once closed.

Type Parameters

Hierarchy

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: T

      The file system that created the file.

    • _path: string
    • _flag: FileFlag
    • _stat: 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.

    • Optional contents: Uint8Array

      A buffer containing the entire contents of the file. PreloadFile will mutate this buffer. If not specified, we assume it is a new file.

    Returns PreloadFile<T>

Properties

_buffer: Uint8Array
_dirty: boolean = false
_flag: FileFlag
_fs: T
_path: string
_pos: number = 0
_stat: Stats

Methods

  • Advance the current file position by the indicated number of positions.

    Parameters

    • delta: number

    Returns number

  • Asynchronous fchmod.

    Parameters

    • mode: number

    Returns Promise<void>

  • Asynchronous fchown.

    Parameters

    • uid: number
    • gid: number

    Returns Promise<void>

  • Core: Asynchronous close. Must be implemented by subclasses of this class.

    Returns Promise<void>

  • Core: Synchronous close.

    Returns void

  • NONSTANDARD: Get the underlying buffer for this file. !!DO NOT MUTATE!! Will mess up dirty tracking.

    Returns Uint8Array

  • Get the path to this file.

    Returns string

    [String] The path to the file.

  • 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

    [Number] The current file position.

  • NONSTANDARD: Get underlying stats for this file. !!DO NOT MUTATE!!

    Returns Stats

  • Read data from the file.

    Parameters

    • buffer: Uint8Array
    • offset: number
    • length: number
    • position: number

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

  • Read data from the file.

    Parameters

    • buffer: Uint8Array
    • offset: number
    • length: number
    • position: number

    Returns number

    [Number]

  • Resets the dirty bit. Should only be called after a sync has completed successfully.

    Returns void

  • Set the file position.

    Parameters

    • newPos: number

    Returns number

  • Core: Asynchronous sync. Must be implemented by subclasses of this class.

    Returns Promise<void>

  • Asynchronous truncate.

    Parameters

    • len: number

    Returns Promise<void>

  • Synchronous truncate.

    Parameters

    • len: number

    Returns void

  • Parameters

    • atime: Date
    • mtime: Date

    Returns Promise<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
    • offset: number
    • length: number
    • position: number

    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
    • offset: number
    • length: number
    • position: number

    Returns number

    [Number]

Generated using TypeDoc