Class FileIndex<T>

A simple class for storing a filesystem index. Assumes that all paths passed to it are absolute paths.

Can be used as a partial or a full index, although care must be taken if used for the former purpose, especially when directories are concerned.

Type Parameters

  • T

Hierarchy

  • FileIndex

Constructors

Properties

_index: {
    [path: string]: IndexDirInode<T>;
}

Type declaration

Methods

  • Split into a (directory path, item name) pair

    Parameters

    • p: string

    Returns string[]

  • Adds the given absolute path to the index if it is not already in the index. Creates any needed parent directories.

    Parameters

    • path: string

      The path to add to the index.

    • inode: IndexInode

      The inode for the path to add.

    Returns boolean

    'True' if it was added or already exists, 'false' if there was an issue adding it (e.g. item in path is a file, item exists but is different).

    Todo

    If adding fails and implicitly creates directories, we do not clean up the new empty directories.

  • Adds the given absolute path to the index if it is not already in the index. The path is added without special treatment (no joining of adjacent separators, etc). Creates any needed parent directories.

    Parameters

    • path: string

      The path to add to the index.

    • inode: IndexInode

      The inode for the path to add.

    Returns boolean

    'True' if it was added or already exists, 'false' if there was an issue adding it (e.g. item in path is a file, item exists but is different).

    Todo

    If adding fails and implicitly creates directories, we do not clean up the new empty directories.

  • Runs the given function over all files in the index.

    Type Parameters

    • T

    Parameters

    • cb: ((file) => void)
        • (file): void
        • Parameters

          • file: T

          Returns void

    Returns void

  • Retrieves the directory listing of the given path.

    Parameters

    • path: string

    Returns string[]

    An array of files in the given path, or 'null' if it does not exist.

  • Removes the given path. Can be a file or a directory.

    Parameters

    • path: string

    Returns IndexInode

    The removed item, or null if it did not exist.

  • Static method for constructing indices from a JSON listing.

    Type Parameters

    • T

    Parameters

    • listing: any

      Directory listing generated by tools/XHRIndexer.coffee

    Returns FileIndex<T>

    A new FileIndex object.

Generated using TypeDoc