@backblaze-labs/b2-sdk - v0.4.0
    Preparing search index...

    Class FileSource

    ContentSource backed by a local filesystem path.

    FileSource is Node-only but safe to import in browser builds: it touches Node filesystem APIs only when constructed or read. The constructor performs synchronous filesystem validation so size is immediately available; request handlers, sync loops, and other latency-sensitive code should use FileSource.fromPath. Both paths capture a best-effort regular file identity and reject a symlink as the final path component; parent directory symlinks are followed by the operating system, so callers that constrain paths under a trusted root should validate those parents separately. Reads reject if the path is replaced, if the filesystem cannot report stable identity on POSIX platforms, or if size/mtime/ctime changes before the configured byte range is read. On Windows, reads avoid unreliable dev/inode identity comparisons and validate size/mtime instead. Slices preserve the captured identity, so multipart uploads can read disjoint ranges without materialising the whole file in memory or following later leaf path swaps.

    Implements

    Index
    canSlice: true

    Random-access: file ranges are read by absolute byte offset.

    size: number

    File size captured at construction time.

    • Return a new file-backed source covering the specified byte range.

      Parameters

      • start: number

        The zero-based byte offset to begin the slice.

      • end: number

        The exclusive byte offset where the slice ends.

      Returns ContentSource

      A new ContentSource representing the requested sub-range.

    • Open this file as a Web ReadableStream.

      Returns ReadableStream<Uint8Array<ArrayBufferLike>>

      A ReadableStream that reads the file lazily.

    • Read this file into an ArrayBuffer.

      Parameters

      • options: { signal?: AbortSignal } = {}

        Optional abort signal used while reading.

      Returns Promise<ArrayBuffer>

      A promise resolving with the file bytes.

    • Create a FileSource using asynchronous filesystem validation.

      Parameters

      Returns Promise<FileSource>

      A FileSource bound to the validated file identity.

      If the path does not reference a regular non-symlink file.

      If a POSIX filesystem cannot report stable file identity.