Options
All
  • Public
  • Public/Protected
  • All
Menu

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

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

Index

Constructors

constructor

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

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

      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

Properties

Protected _fs

_fs: T

Methods

advancePos

  • advancePos(delta: number): number
  • Advance the current file position by the indicated number of positions.

    Parameters

    • delta: number

    Returns number

chmod

chmodSync

  • chmodSync(mode: number): void

chown

chownSync

  • chownSync(uid: number, gid: number): void

close

closeSync

  • closeSync(): void

datasync

datasyncSync

  • datasyncSync(): void

getBuffer

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

    Returns Buffer

getFlag

getPath

  • getPath(): string

getPos

  • getPos(): 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.

getStats

Protected isDirty

  • isDirty(): boolean

read

  • read(buffer: Buffer, offset: number, length: number, position: number, cb: BFSThreeArgCallback<number, Buffer>): void
  • Read data from the file.

    Parameters

    • buffer: Buffer

      The buffer that the data will be written to.

    • offset: number

      The offset within the buffer where writing will start.

    • length: number

      An integer specifying the number of bytes to read.

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

    • cb: BFSThreeArgCallback<number, Buffer>

      The number is the number of bytes read

    Returns void

readSync

  • readSync(buffer: Buffer, offset: number, length: number, position: number): number
  • Read data from the file.

    Parameters

    • buffer: Buffer

      The buffer that the data will be written to.

    • offset: number

      The offset within the buffer where writing will start.

    • length: number

      An integer specifying the number of bytes to read.

    • 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

Protected resetDirty

  • resetDirty(): void
  • Resets the dirty bit. Should only be called after a sync has completed successfully.

    Returns void

setPos

  • setPos(newPos: number): number

stat

statSync

sync

syncSync

  • syncSync(): void

truncate

truncateSync

  • truncateSync(len: number): void

utimes

utimesSync

  • utimesSync(atime: Date, mtime: Date): void

write

  • write(buffer: Buffer, offset: number, length: number, position: number, cb: BFSThreeArgCallback<number, Buffer>): 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: Buffer

      Buffer containing the data to write to the file.

    • offset: number

      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.

    • cb: BFSThreeArgCallback<number, Buffer>

    Returns void

writeSync

  • writeSync(buffer: Buffer, offset: number, length: number, position: number): 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: Buffer

      Buffer containing the data to write to the file.

    • offset: number

      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

Generated using TypeDoc