Interface FsClient

An interface that abstracts file system operations.

You need to pass a file system client into Git commands that do anything that involves files (which is most things in Git).

In Node.js, you can pass the builtin fs/promises module. In the browser it's more involved because there's no standard fs module. But you can use any module that implements enough of the fs API.

Node.js

If you're only using the library in Node.js, you can just use the native fs/promises module:

import fs from 'fs/promises'
import { listFiles } from 'git-essentials'

const files = await listFiles({ fs, dir: dirname })
console.log(files)

Browser

For testing purposes, the library includes in-memory file system implementations which can be used on both Node.js and browser environments. For persistent production use, you will have to use 3rd party clients/build-in clients in this package or your own implementation.

import { InMemoryFsClient } from 'git-essentials/clients/fs/InMemoryFsClient'
import { listFiles } from 'git-essentials'

const fs = new InMemoryFsClient()
const files = await listFiles({ fs, dir: dirname })
console.log(files)

Hierarchy

  • FsClient

Implemented by

Methods

  • Returns information about the given file or directory.

    Remarks

    The method is similar to the stat method except it doesn't follow symlinks. When given a path that is a symlink it returns the stat of the symlink and not its target.

    Throws

    ENOENT

    Parameters

    • path: string

    Returns Promise<StatsLike>

  • Asynchronously reads the entire contents of a file.

    Returns

    Resolves with the contents of the file as an Uint8Array or a string if the encoding is set to utf8.

    Throws

    ENOENT

    Parameters

    Returns Promise<string | Uint8Array>

  • Returns a symbolic link’s value, i.e. the path it is linked to.

    Throws

    ENOENT

    Parameters

    • path: string

    Returns Promise<string>

  • Renames oldPath to newPath.

    Throws

    ENOENT

    Parameters

    • oldPath: string
    • newPath: string

    Returns Promise<void>

  • Returns information about the given file or directory.

    Remarks

    The method follows symlinks. When given a path that is a symlink, it returns the stat of the target of the symlink.

    Throws

    ENOENT

    Parameters

    • path: string

    Returns Promise<StatsLike>

  • Creates a symbolic link.

    Throws

    ENOENT

    Parameters

    • target: string
    • path: string

    Returns Promise<void>

  • Asynchronously writes data to a file, replacing the file if it already exists.

    Remarks

    Data can be a string or an Uint8Array. The encoding option is ignored if data is an Uint8Array.

    Throws

    ENOENT

    Parameters

    • path: string
    • data: string | Uint8Array
    • Optional options: WriteOptions

    Returns Promise<void>

Generated using TypeDoc