path-scurry
    Preparing search index...

    Class PathBaseAbstract

    Path objects are sort of like a super-powered fs.Dirent

    Each one represents a single filesystem entry on disk, which may or may not exist. It includes methods for reading various types of information via lstat, readlink, and readdir, and caches all information to the greatest degree possible.

    Note that fs operations that would normally throw will instead return an "empty" value. This is in order to prevent excessive overhead from error stack traces.

    Hierarchy (View Summary)

    Implements

    • Dirent
    Index

    Constructors

    • Internal

      Do not create new Path objects directly. They should always be accessed via the PathScurry class or other methods on the Path class.

      Parameters

      Returns PathBase

    Properties

    isCWD: boolean = false

    boolean indicating that this path is the current working directory of the PathScurry collection that contains it.

    name: string

    the basename of this path

    Important: always test the path name against any test string usingthe isNamed method, and not by directly comparing this string. Otherwise, unicode path strings that the system sees as identical will not be properly treated as the same path, leading to incorrect behavior and possible security issues.

    nocase: boolean

    boolean indicating whether paths are compared case-insensitively

    parent?: PathBase

    a reference to the parent path, or undefined in the case of root entries

    root: PathBase

    the Path entry corresponding to the path root.

    roots: { [k: string]: PathBase }

    All roots found within the current PathScurry family

    sep: string

    The path separator string to use when joining paths

    splitSep: string | RegExp

    the string or regexp used to split paths. On posix, it is '/', and on windows it is a RegExp matching either '/' or '\\'

    Accessors

    • get atime(): Date | undefined

      Returns Date | undefined

    • get atimeMs(): number | undefined

      Returns number | undefined

    • get birthtime(): Date | undefined

      Returns Date | undefined

    • get birthtimeMs(): number | undefined

      Returns number | undefined

    • get blksize(): number | undefined

      Returns number | undefined

    • get blocks(): number | undefined

      Returns number | undefined

    • get ctime(): Date | undefined

      Returns Date | undefined

    • get ctimeMs(): number | undefined

      Returns number | undefined

    • get dev(): number | undefined

      Returns number | undefined

    • get gid(): number | undefined

      Returns number | undefined

    • get ino(): number | undefined

      Returns number | undefined

    • get mode(): number | undefined

      Returns number | undefined

    • get mtime(): Date | undefined

      Returns Date | undefined

    • get mtimeMs(): number | undefined

      Returns number | undefined

    • Returns number | undefined

    • get parentPath(): string

      This property is for compatibility with the Dirent class as of Node v20, where Dirent['parentPath'] refers to the path of the directory that was passed to readdir. For root entries, it's the path to the entry itself.

      Returns string

    • get path(): string

      Deprecated alias for Dirent['parentPath'] Somewhat counterintuitively, this property refers to the parent path, not the path object itself.

      Returns string

    • get rdev(): number | undefined

      Returns number | undefined

    • get size(): number | undefined

      Returns number | undefined

    • get uid(): number | undefined

      Returns number | undefined

    Methods

    • Internal

      Internal method to mark this Path object as the scurry cwd, called by PathScurry#chdir

      Parameters

      Returns void

    • Return true if readdir has previously been successfully called on this path, indicating that cachedReaddir() is likely valid.

      Returns boolean

    • Return true if it's worth trying to readlink. Ie, we don't (yet) have any indication that readlink will definitely fail.

      Returns false if the path is known to not be a symlink, if a previous readlink failed, or if the entry does not exist.

      Returns boolean

    • Internal

      Resolves a path portion and returns or creates the child Path.

      Returns this if pathPart is '' or '.', or parent if pathPart is '..'.

      This should not be called directly. If pathPart contains any path separators, it will lead to unsafe undefined behavior.

      Use Path.resolve() instead.

      Parameters

      Returns PathBase

    • Internal

      Returns the cached children Path objects, if still available. If they have fallen out of the cache, then returns an empty array, and resets the READDIR_CALLED bit, so that future calls to readdir() will require an fs lookup.

      Returns Children

    • Returns the depth of the Path object from its root.

      For example, a path at /foo/bar would have a depth of 2.

      Returns number

    • The fully resolved path string for this Path entry

      Returns string

    • On platforms other than windows, this is identical to fullpath.

      On windows, this is overridden to return the forward-slash form of the full UNC path.

      Returns string

    • Internal

      Parameters

      • path: string

      Returns string

    • Is the path a block device?

      Returns boolean

    • Is the path a character device?

      Returns boolean

    • Is the Path a directory?

      Returns boolean

    • Returns true if the path is known to not exist. That is, a previous lstat or readdir failed to verify its existence when that would have been expected, or a parent entry was marked either enoent or enotdir.

      Returns boolean

    • Is the path a FIFO pipe?

      Returns boolean

    • Is the Path a regular file?

      Returns boolean

    • Return true if the path is a match for the given path name. This handles case sensitivity and unicode normalization.

      Note: even on case-sensitive systems, it is not safe to test the equality of the .name property to determine whether a given pathname matches, due to unicode normalization mismatches.

      Always use this method instead of testing the path.name property directly.

      Parameters

      • n: string

      Returns boolean

    • Is the path a socket?

      Returns boolean

    • Is the path a symbolic link?

      Returns boolean

    • Is the Path of an unknown type?

      Note that we might know something about it if there has been a previous filesystem operation, for example that it does not exist, or is not a link, or whether it has child entries.

      Returns boolean

    • Call lstat() on this Path, and update all known information that can be determined.

      Note that unlike fs.lstat(), the returned value does not contain some information, such as mode, dev, nlink, and ino. If that information is required, you will need to call fs.lstat yourself.

      If the Path refers to a nonexistent file, or if the lstat call fails for any reason, undefined is returned. Otherwise the updated Path object is returned.

      Results are cached, and thus may be out of date if the filesystem is mutated.

      Returns Promise<PathBase | undefined>

    • Return the entry if it has been subject of a successful lstat, or undefined otherwise.

      Does not read the filesystem, so an undefined result could simply mean that we haven't called lstat on it.

      Returns PathBase | undefined

    • Return an array of known child entries.

      If the Path cannot or does not contain any children, then an empty array is returned.

      Results are cached, and thus may be out of date if the filesystem is mutated.

      Returns Promise<PathBase[]>

    • Returns the cached child Path entries array if the entry has been the subject of a successful readdir(), or [] otherwise.

      Does not read the filesystem, so an empty array could just mean we don't have any cached data. Only use it if you are very sure that a readdir() has been called recently enough to still be valid.

      Returns PathBase[]

    • Standard node-style callback interface to get list of directory entries.

      If the Path cannot or does not contain any children, then an empty array is returned.

      Results are cached, and thus may be out of date if the filesystem is mutated.

      Parameters

      • cb: (er: ErrnoException | null, entries: PathBase[]) => any

        The callback called with (er, entries). Note that the er param is somewhat extraneous, as all readdir() errors are handled and simply result in an empty set of entries being returned.

      • allowZalgo: boolean = false

        Boolean indicating that immediately known results should not be deferred with queueMicrotask. Defaults to false. Release zalgo at your peril, the dark pony lord is devious and unforgiving.

      Returns void

    • Return the Path object corresponding to the target of a symbolic link.

      If the Path is not a symbolic link, or if the readlink call fails for any reason, undefined is returned.

      Result is cached, and thus may be outdated if the filesystem is mutated.

      Returns Promise<PathBase | undefined>

    • Return the cached link target if the entry has been the subject of a successful readlink, or undefined otherwise.

      Does not read the filesystem, so an undefined result could just mean we don't have any cached data. Only use it if you are very sure that a readlink() has been called at some point.

      Returns PathBase | undefined

    • Return the Path object corresponding to path as resolved by realpath(3).

      If the realpath call fails for any reason, undefined is returned.

      Result is cached, and thus may be outdated if the filesystem is mutated. On success, returns a Path object.

      Returns Promise<PathBase | undefined>

    • Returns the cached realpath target if the entry has been the subject of a successful realpath, or undefined otherwise.

      Does not read the filesystem, so an undefined result could just mean we don't have any cached data. Only use it if you are very sure that a realpath() has been called at some point.

      Returns PathBase | undefined

    • The relative path from the cwd. If it does not share an ancestor with the cwd, then this ends up being equivalent to the fullpath()

      Returns string

    • The relative path from the cwd, using / as the path separator. If it does not share an ancestor with the cwd, then this ends up being equivalent to the fullpathPosix() On posix systems, this is identical to relative().

      Returns string

    • Get the Path object referenced by the string path, resolved from this Path

      Parameters

      • Optionalpath: string

      Returns PathBase