Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface FileSystem

Interface for a filesystem. All BrowserFS FileSystems should implement this interface.

Below, we denote each API method as Core, Supplemental, or Optional.

Core Methods

Core API methods need to be implemented for basic read/write functionality.

Note that read-only FileSystems can choose to not implement core methods that mutate files or metadata. The default implementation will pass a NOT_SUPPORTED error to the callback.

Supplemental Methods

Supplemental API methods do not need to be implemented by a filesystem. The default implementation implements all of the supplemental API methods in terms of the core API methods.

Note that a file system may choose to implement supplemental methods for efficiency reasons.

The code for some supplemental methods was adapted directly from NodeJS's fs.js source code.

Optional Methods

Optional API methods provide functionality that may not be available in all filesystems. For example, all symlink/hardlink-related API methods fall under this category.

The default implementation will pass a NOT_SUPPORTED error to the callback.

Argument Assumptions

You can assume the following about arguments passed to each API method:

  • Every path is an absolute path. Meaning, ., .., and other items are resolved into an absolute form.
  • All arguments are present. Any optional arguments at the Node API level have been passed in with their default values.
  • The callback will reset the stack depth. When your filesystem calls the callback with the requested information, it will use setImmediate to reset the JavaScript stack depth before calling the user-supplied callback.

Hierarchy

  • FileSystem

Implemented by

Index

Methods

appendFile

  • appendFile(fname: string, data: string | Buffer, encoding: string | null, flag: FileFlag, mode: number, cb: BFSOneArgCallback): void
  • Supplemental: Asynchronously append data to a file, creating the file if it not yet exists.

    Parameters

    Returns void

appendFileSync

  • appendFileSync(fname: string, data: string | Buffer, encoding: string | null, flag: FileFlag, mode: number): void
  • Supplemental: Synchronously append data to a file, creating the file if it not yet exists.

    Parameters

    • fname: string
    • data: string | Buffer
    • encoding: string | null
    • flag: FileFlag
    • mode: number

    Returns void

chmod

  • Optional: Asynchronous chmod or lchmod.

    Parameters

    • p: string
    • isLchmod: boolean

      True if lchmod, false if chmod. Has no bearing on result if links aren't supported.

    • mode: number
    • cb: BFSOneArgCallback

    Returns void

chmodSync

  • chmodSync(p: string, isLchmod: boolean, mode: number): void
  • Optional: Synchronous chmod or lchmod.

    Parameters

    • p: string
    • isLchmod: boolean

      True if lchmod, false if chmod. Has no bearing on result if links aren't supported.

    • mode: number

    Returns void

chown

  • chown(p: string, isLchown: boolean, uid: number, gid: number, cb: BFSOneArgCallback): void
  • Optional: Asynchronous chown or lchown.

    Parameters

    • p: string
    • isLchown: boolean

      True if lchown, false if chown. Has no bearing on result if links aren't supported.

    • uid: number
    • gid: number
    • cb: BFSOneArgCallback

    Returns void

chownSync

  • chownSync(p: string, isLchown: boolean, uid: number, gid: number): void
  • Optional: Synchronous chown or lchown.

    Parameters

    • p: string
    • isLchown: boolean

      True if lchown, false if chown. Has no bearing on result if links aren't supported.

    • uid: number
    • gid: number

    Returns void

diskSpace

  • diskSpace(p: string, cb: function): void
  • Optional: Passes the following information to the callback:

    • Total number of bytes available on this file system.
    • number of free bytes available on this file system.
    todo

    This info is not available through the Node API. Perhaps we could do a polyfill of diskspace.js, or add a new Node API function.

    Parameters

    • p: string
    • cb: function
        • (total: number, free: number): any
        • Parameters

          • total: number
          • free: number

          Returns any

    Returns void

exists

  • exists(p: string, cb: function): void
  • Supplemental: Test whether or not the given path exists by checking with the file system. Then call the callback argument with either true or false.

    Parameters

    • p: string
    • cb: function
        • (exists: boolean): void
        • Parameters

          • exists: boolean

          Returns void

    Returns void

existsSync

  • existsSync(p: string): boolean
  • Supplemental: Test whether or not the given path exists by checking with the file system.

    Parameters

    • p: string

    Returns boolean

getName

  • getName(): string

isReadOnly

  • isReadOnly(): boolean
  • Core: Is this filesystem read-only?

    Returns boolean

    True if this FileSystem is inherently read-only.

link

linkSync

  • linkSync(srcpath: string, dstpath: string): void
  • Optional: Synchronous link.

    Parameters

    • srcpath: string
    • dstpath: string

    Returns void

mkdir

  • Core: Asynchronous mkdir.

    Parameters

    • p: string
    • mode: number

      Mode to make the directory using. Can be ignored if the filesystem doesn't support permissions.

    • cb: BFSOneArgCallback

    Returns void

mkdirSync

  • mkdirSync(p: string, mode: number): void
  • Core: Synchronous mkdir.

    Parameters

    • p: string
    • mode: number

      Mode to make the directory using. Can be ignored if the filesystem doesn't support permissions.

    Returns void

open

openSync

readFile

  • Supplemental: Asynchronously reads the entire contents of a file.

    Parameters

    • fname: string
    • encoding: string | null

      If non-null, the file's contents should be decoded into a string using that encoding. Otherwise, if encoding is null, fetch the file's contents as a Buffer.

    • flag: FileFlag
    • cb: BFSCallback

      If no encoding is specified, then the raw buffer is returned.

    Returns void

readFileSync

  • readFileSync(fname: string, encoding: string | null, flag: FileFlag): any
  • Supplemental: Synchronously reads the entire contents of a file.

    Parameters

    • fname: string
    • encoding: string | null

      If non-null, the file's contents should be decoded into a string using that encoding. Otherwise, if encoding is null, fetch the file's contents as a Buffer.

    • flag: FileFlag

    Returns any

readdir

  • Core: Asynchronous readdir. Reads the contents of a directory.

    The callback gets two arguments (err, files) where files is an array of the names of the files in the directory excluding '.' and '..'.

    Parameters

    Returns void

readdirSync

  • readdirSync(p: string): string[]
  • Core: Synchronous readdir. Reads the contents of a directory.

    Parameters

    • p: string

    Returns string[]

readlink

readlinkSync

  • readlinkSync(p: string): string

realpath

  • realpath(p: string, cache: object, cb: BFSCallback): void
  • Supplemental: Asynchronous realpath. The callback gets two arguments (err, resolvedPath).

    Note that the Node API will resolve path to an absolute path.

    Parameters

    • p: string
    • cache: object

      An object literal of mapped paths that can be used to force a specific path resolution or avoid additional fs.stat calls for known real paths. If not supplied by the user, it'll be an empty object.

      • [path: string]: string
    • cb: BFSCallback

    Returns void

realpathSync

  • realpathSync(p: string, cache: object): string
  • Supplemental: Synchronous realpath.

    Note that the Node API will resolve path to an absolute path.

    Parameters

    • p: string
    • cache: object

      An object literal of mapped paths that can be used to force a specific path resolution or avoid additional fs.stat calls for known real paths. If not supplied by the user, it'll be an empty object.

      • [path: string]: string

    Returns string

rename

  • Core: Asynchronous rename. No arguments other than a possible exception are given to the completion callback.

    Parameters

    Returns void

renameSync

  • renameSync(oldPath: string, newPath: string): void
  • Core: Synchronous rename.

    Parameters

    • oldPath: string
    • newPath: string

    Returns void

rmdir

rmdirSync

  • rmdirSync(p: string): void

stat

  • stat(p: string, isLstat: boolean | null, cb: BFSCallback): void
  • Core: Asynchronous stat or lstat.

    Parameters

    • p: string
    • isLstat: boolean | null

      True if this is lstat, false if this is regular stat.

    • cb: BFSCallback

    Returns void

statSync

  • statSync(p: string, isLstat: boolean | null): Stats
  • Core: Synchronous stat or lstat.

    Parameters

    • p: string
    • isLstat: boolean | null

      True if this is lstat, false if this is regular stat.

    Returns Stats

supportsLinks

  • supportsLinks(): boolean
  • Core: Does the filesystem support optional symlink/hardlink-related commands?

    Returns boolean

    True if the FileSystem supports the optional symlink/hardlink-related commands.

supportsProps

  • supportsProps(): boolean
  • Core: Does the filesystem support optional property-related commands?

    Returns boolean

    True if the FileSystem supports the optional property-related commands (permissions, utimes, etc).

supportsSynch

  • supportsSynch(): boolean
  • Core: Does the filesystem support the optional synchronous interface?

    Returns boolean

    True if the FileSystem supports synchronous operations.

symlink

  • symlink(srcpath: string, dstpath: string, type: string, cb: BFSOneArgCallback): void

symlinkSync

  • symlinkSync(srcpath: string, dstpath: string, type: string): void
  • Optional: Synchronous symlink.

    Parameters

    • srcpath: string
    • dstpath: string
    • type: string

      can be either 'dir' or 'file'

    Returns void

truncate

truncateSync

  • truncateSync(p: string, len: number): void
  • Supplemental: Synchronous truncate.

    Parameters

    • p: string
    • len: number

    Returns void

unlink

unlinkSync

  • unlinkSync(p: string): void

utimes

utimesSync

  • utimesSync(p: string, atime: Date, mtime: Date): void
  • Optional: Change file timestamps of the file referenced by the supplied path.

    Parameters

    • p: string
    • atime: Date
    • mtime: Date

    Returns void

writeFile

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

    The encoding option is ignored if data is a buffer.

    Parameters

    Returns void

writeFileSync

  • writeFileSync(fname: string, data: string | Buffer, encoding: string | null, flag: FileFlag, mode: number): void
  • Supplemental: Synchronously writes data to a file, replacing the file if it already exists.

    The encoding option is ignored if data is a buffer.

    Parameters

    • fname: string
    • data: string | Buffer
    • encoding: string | null
    • flag: FileFlag
    • mode: number

    Returns void

Generated using TypeDoc