Class representing some kind of filesystem resource.

Hierarchy

  • UniversalPath

Constructors

Properties

filesystem?: Filesystem
initial: string

The path string this path refers to.

Example

/home/user/file.txt

Example

https://site.com/file.txt
resourceLocalPath: string
resourcePrefix: string
resourceQuery: URLSearchParams = ...

Accessors

  • get contentType(): string | false
  • Get the content-type header of this resource.

    Returns string | false

  • get ext(): string
  • Get the extension of the resource referred to by this instance.

    Example

    const myFile = universalPath('home', 'user', 'file.txt')

    myFile.ext // => 'txt'

    Returns string

  • get isLocal(): boolean
  • Returns true if this resource refers to a file on the local filesystem.

    Returns boolean

  • get isRemote(): boolean
  • Returns true if this resource refers to a file on a remote filesystem.

    Returns boolean

  • get toLocal(): string
  • Get the path to this resource as it would be accessed from the current filesystem.

    Returns string

Methods

  • Append and resolve the given paths to this resource and return a new UniversalPath.

    Example

    const homeDir = universalPath('home', 'user')

    homeDir.concat('file.txt').toLocal // => /home/user/file.txt

    homeDir.concat('..', 'other_user').toLocal // => /home/other_user

    Parameters

    Returns UniversalPath

  • Returns true if the given resource exists at the path.

    Returns Promise<boolean>

  • Resolves true if this resource is a directory.

    Returns Promise<boolean>

  • Resolves true if this resource is a regular file.

    Returns Promise<boolean>

  • Recursively create this path as a directory. Equivalent to mkdir -p on Linux.

    Returns Promise<void>

  • Read the data from this resource's file as a string.

    Returns Promise<string>

  • Get a readable stream of this file's contents.

    Returns Promise<Readable>

  • Protected

    Determine the "localized" string of this path.

    This is the normalized path WITHOUT the prefix.

    Example

    The normalized path of "file:///home/user/file.txt" is "/home/user/file.txt".

    @protected

    Returns void

  • Get the size of this resource, formatted in a human-readable string.

    Returns Promise<string>

  • Recursively walk all files in this directory. Must be a local resource.

    This returns an async generator function.

    Example

    const configFiles = universalPath('home', 'user', '.config')

    for await (const configFile of configFiles.walk()) {
    // configFile is a string
    // ... do something ...
    }

    Returns any

  • Write the given data to this resource as a file.

    Parameters

    • data: string | Buffer

    Returns Promise<void>

  • Get a writable stream to this file's contents.

    Returns Promise<Writable>