Options
All
  • Public
  • Public/Protected
  • All
Menu

Class XmlHttpRequest

A simple filesystem backed by XMLHttpRequests.

Hierarchy

Implements

Index

Constructors

constructor

  • new XmlHttpRequest(listingUrlOrObj: string | any, prefixUrl?: string): XmlHttpRequest
  • Constructs the file system. You must provide the directory listing as a JSON object produced by the make_xhrfs_index script.

    If you install BrowserFS globally with npm i -g browserfs, you can generate a listing by running make_xhrfs_index in your terminal in the directory you would like to index:

    make_xhrfs_index > index.json
    

    Listings objects look like the following:

    {
      "home": {
        "jvilk": {
          "someFile.txt": null,
          "someDir": {
            // Empty directory
          }
        }
      }
    }
    

    This example has the folder /home/jvilk with subfile someFile.txt and subfolder someDir.

    Alternatively, you can construct an XmlHttpRequest object by calling the static FromURL function:

    BrowserFS.FileSystem.XmlHttpRequest.FromURL('http://example.com/files/index.json');
    

    DEPRECATED: You may pass a URL to the file index to the constructor, which will fetch the file index synchronously and may freeze up the web page. This behavior will be removed in the next major version of BrowserFS.

    Parameters

    • listingUrlOrObj: string | any

      index object or the path to the JSON file index generated by make_xhrfs_index.

    • Default value prefixUrl: string = ""

      URL that is prepended to any file locations in the file index. e.g. if prefixUrl = 'data/, and the user wants to open the file /foo.txt, the file system will fetch file data/foo.txt. The browser will access the file relative to the currrent webpage URL.

    Returns XmlHttpRequest

Properties

prefixUrl

prefixUrl: string

Methods

appendFile

appendFileSync

  • appendFileSync(fname: string, data: any, encoding: string | null, flag: FileFlag, mode: number): void

chmod

chmodSync

  • chmodSync(p: string, isLchmod: boolean, mode: number): void

chown

  • chown(p: string, isLchown: boolean, uid: number, gid: number, cb: BFSOneArgCallback): void

chownSync

  • chownSync(p: string, isLchown: boolean, uid: number, gid: number): void

createFile

createFileSync

  • createFileSync(p: string, flag: FileFlag, mode: number): File

diskSpace

  • diskSpace(path: string, cb: function): void

empty

  • empty(): void

exists

  • exists(p: string, cb: function): void

existsSync

  • existsSync(p: string): boolean

getName

  • getName(): string

isReadOnly

  • isReadOnly(): boolean

link

linkSync

  • linkSync(srcpath: string, dstpath: string): void

mkdir

mkdirSync

  • mkdirSync(p: string, mode: number): void

open

openFile

openFileSync

  • openFileSync(p: string, flag: FileFlag, mode: number): File
  • Opens the file at path p with the given flag. The file must exist.

    Parameters

    • p: string

      The path to open.

    • flag: FileFlag

      The flag to use when opening the file.

    • mode: number

    Returns File

    A File object corresponding to the opened file.

openSync

  • openSync(path: string, flags: FileFlag, mode: number): File

preloadFile

  • preloadFile(path: string, buffer: Buffer): void
  • Special XHR function: Preload the given file into the index.

    Parameters

    • path: string
    • buffer: Buffer

    Returns void

readFile

readFileSync

  • readFileSync(fname: string, encoding: string, flag: FileFlag): any

readdir

readdirSync

  • readdirSync(path: string): string[]

readlink

readlinkSync

  • readlinkSync(p: string): string

realpath

  • realpath(p: string, cache: object, cb: BFSCallback): void

realpathSync

  • realpathSync(p: string, cache: object): string

rename

renameSync

  • renameSync(oldPath: string, newPath: string): void

rmdir

rmdirSync

  • rmdirSync(p: string): void

stat

  • stat(path: string, isLstat: boolean, cb: BFSCallback): void

statSync

  • statSync(path: string, isLstat: boolean): Stats

supportsLinks

  • supportsLinks(): boolean

supportsProps

  • supportsProps(): boolean

supportsSynch

  • supportsSynch(): boolean

symlink

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

symlinkSync

  • symlinkSync(srcpath: string, dstpath: string, type: string): void

truncate

truncateSync

  • truncateSync(p: string, len: number): void

unlink

unlinkSync

  • unlinkSync(p: string): void

utimes

utimesSync

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

writeFile

writeFileSync

  • writeFileSync(fname: string, data: any, encoding: string | null, flag: FileFlag, mode: number): void

Static FromURL

  • FromURL(url: string, cb: function, baseUrl?: string): void
  • Constructs an XmlHttpRequest object using the directory listing at the given URL. Uses the base URL as the URL prefix for fetched files.

    Parameters

    • url: string
    • cb: function

      Called when the file system has been instantiated, or if an error occurs.

    • Default value baseUrl: string = url.slice(0, url.lastIndexOf('/') + 1)

    Returns void

Static isAvailable

  • isAvailable(): boolean

Generated using TypeDoc