Options
All
  • Public
  • Public/Protected
  • All
Menu

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

Index

Constructors

constructor

Methods

addPath

  • addPath(path: string, inode: Inode): boolean
  • Adds the given absolute path to the index if it is not already in the index. Creates any needed parent directories.

    todo

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

    Parameters

    • path: string

      The path to add to the index.

    • inode: Inode

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

addPathFast

  • addPathFast(path: string, inode: Inode): boolean
  • 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.

    todo

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

    Parameters

    • path: string

      The path to add to the index.

    • inode: Inode

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

fileIterator

  • fileIterator<T>(cb: function): void
  • Runs the given function over all files in the index.

    Type parameters

    • T

    Parameters

    • cb: function
        • (file: T | null): void
        • Parameters

          • file: T | null

          Returns void

    Returns void

getInode

  • getInode(path: string): Inode | null
  • Returns the inode of the given item.

    Parameters

    • path: string

    Returns Inode | null

    Returns null if the item does not exist.

ls

  • ls(path: string): string[] | null
  • Retrieves the directory listing of the given path.

    Parameters

    • path: string

    Returns string[] | null

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

removePath

  • removePath(path: string): Inode | null
  • Removes the given path. Can be a file or a directory.

    Parameters

    • path: string

    Returns Inode | null

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

Static fromListing

  • 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