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

Implements

  • Dirent

Constructors

Properties

#asyncReaddirInFlight?: Promise<void>
#atime?: Date
#atimeMs?: number
#birthtime?: Date
#birthtimeMs?: number
#blksize?: number
#blocks?: number
#children: ChildrenCache
#ctime?: Date
#ctimeMs?: number
#depth?: number
#dev?: number
#fs: FSValue
#fullpath?: string
#fullpathPosix?: string
#gid?: number
#ino?: number
#linkTarget?: PathBase
#matchName: string
#mode?: number
#mtime?: Date
#mtimeMs?: number
#nlink?: number
#onReaddirCB: ((er: null | ErrnoException, entries: Path[]) => any)[] = []
#rdev?: number
#readdirCBInFlight: boolean = false
#realpath?: PathBase
#relative?: string
#relativePosix?: string
#size?: number
#type: number
#uid?: number
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

Type declaration

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(): undefined | Date
  • Returns undefined | Date

  • get atimeMs(): undefined | number
  • Returns undefined | number

  • get birthtime(): undefined | Date
  • Returns undefined | Date

  • get birthtimeMs(): undefined | number
  • Returns undefined | number

  • get blksize(): undefined | number
  • Returns undefined | number

  • get blocks(): undefined | number
  • Returns undefined | number

  • get ctime(): undefined | Date
  • Returns undefined | Date

  • get ctimeMs(): undefined | number
  • Returns undefined | number

  • get dev(): undefined | number
  • Returns undefined | number

  • get gid(): undefined | number
  • Returns undefined | number

  • get ino(): undefined | number
  • Returns undefined | number

  • get mode(): undefined | number
  • Returns undefined | number

  • get mtime(): undefined | Date
  • Returns undefined | Date

  • get mtimeMs(): undefined | number
  • Returns undefined | number

  • Returns undefined | number

  • get path(): string
  • This property is for compatibility with the Dirent class as of Node v20, where Dirent['path'] refers to the path of the directory that was passed to readdir. So, somewhat counterintuitively, this property refers to the parent path, not the path object itself. For root entries, it's the path to the entry itself.

    Returns string

  • get rdev(): undefined | number
  • Returns undefined | number

  • get size(): undefined | number
  • Returns undefined | number

  • get uid(): undefined | number
  • Returns undefined | number

Methods

  • Parameters

    • st: Stats

    Returns void

  • Parameters

    • code: string = ''

    Returns void

  • Parameters

    • code: string = ''

    Returns void

  • Parameters

    • code: string = ''

    Returns void

  • 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

    • pathPart: string
    • Optional opts: PathOpts

    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<undefined | PathBase>

  • 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 undefined | PathBase

  • 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[]>

  • 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: null | ErrnoException, 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.

        • (er: null | ErrnoException, entries: PathBase[]): any
        • Parameters

          • er: null | ErrnoException
          • entries: PathBase[]

          Returns any

    • 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

  • 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[]

  • 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<undefined | PathBase>

  • 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 undefined | PathBase

  • 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<undefined | PathBase>

  • 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 undefined | PathBase

  • 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

    • Optional path: string

    Returns PathBase

Generated using TypeDoc