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

    Class B2Object

    Handle to a specific file (by name) within a B2 bucket.

    Provides file-scoped upload, download, and management operations. Obtained via Bucket.file.

    const obj = bucket.file('photos/2026/sunset.jpg')
    await obj.upload({ source: new BufferSource(data) })
    const result = await obj.download()
    Index
    fileName: string

    The file name (path) within the bucket.

    • Creates a parallel-download ReadableStream that fetches the file in concurrent ranged chunks. Retryable range-body failures, such as a connection reset, use the client's retry.maxRetries setting (default 5). Partial range bytes are discarded before retrying. Each new range request has its own transport retry budget, so the setting is not a total HTTP request limit. Set it to 0 on the client to disable transient request and range-body retries; expired-token reauthorization remains separate. There is no per-call retry override here. rangeSize must be positive and concurrency must be a positive integer, including for an empty file.

      Parameters

      • fileId: FileId

        The file version ID to download.

      • totalSize: number

        Total file size in bytes (needed to compute range boundaries).

      • Optionaloptions: {
            concurrency?: number;
            rangeSize?: number;
            serverSideEncryption?: SseCKeyMaterial;
            signal?: AbortSignal;
        }

        Concurrency, range size, SSE-C decryption, and abort signal.

        • Optionalconcurrency?: number

          Number of concurrent range requests. Must be a positive integer. Defaults to 4.

        • OptionalrangeSize?: number

          Size of each ranged GET request in bytes. Must be positive. Defaults to 10 MB.

        • OptionalserverSideEncryption?: SseCKeyMaterial

          SSE-C decryption parameters, required if the file was uploaded with SSE-C.

        • Optionalsignal?: AbortSignal

          Abort signal for cancelling the download.

      Returns ReadableStream<Uint8Array<ArrayBufferLike>>

      A Web ReadableStream of file data in sequential order.

      A RangeError synchronously if rangeSize is not positive or concurrency is not a positive integer.

    • Creates a Web WritableStream that uploads streamed data into this file. Streams of one part or less finish through a single-request upload; larger streams use the multipart protocol. At exactly one part, the provisional large file is cancelled and the bytes are uploaded again as a single file. Closing a stream without writing any data rejects. Pipe a ReadableStream<Uint8Array> into the returned writable and await done to get the final FileVersion.

      Note: streaming uploads do not support resume because the size and per-part hashes are not known in advance. Use upload with a buffered source when resume is required.

      Parameters

      Returns UploadWriteHandle

      A handle with the writable sink and a completion promise.

    • Permanently deletes a specific version of this file.

      Parameters

      • fileId: FileId

        The unique identifier of the file version to delete.

      Returns Promise<void>

    • Downloads this file by name. Pass method: 'HEAD' to fetch only the response headers (file metadata) without streaming the body.

      Parameters

      • Optionaloptions: DownloadCallOptions

        Optional method, range, SSE-C decryption, response-header overrides, and abort signal.

      Returns Promise<DownloadResult>

      The download result with response headers and body stream.

    • Downloads a specific version of this file by ID. Pass method: 'HEAD' to fetch only the response headers (file metadata) without streaming the body.

      Parameters

      • fileId: FileId

        The file version ID to download.

      • Optionaloptions: DownloadCallOptions

        Optional method, range, SSE-C decryption, response-header overrides, and abort signal.

      Returns Promise<DownloadResult>

      The download result with response headers and body stream.

    • Retrieves metadata for a specific file version.

      Parameters

      • fileId: FileId

        The file version ID to look up.

      Returns Promise<FileVersion>

      The file version metadata.

    • Fetches response headers for this file via HTTP HEAD. Returns a body-less result so callers never have to drain the (logically empty) HEAD body themselves.

      Parameters

      • Optionaloptions: HeadCallOptions

        Optional range, SSE-C decryption, response-header overrides, and abort signal. Same shape as B2Object.download's options minus method (always HEAD) and onProgress (no body).

      Returns Promise<HeadResult>

      Parsed download headers (content type, SHA-1, file info, etc.).

    • Fetches response headers for a specific version of this file by ID via HTTP HEAD. Returns a body-less result so callers never have to drain the (logically empty) HEAD body themselves.

      Parameters

      • fileId: FileId

        The file version ID to inspect.

      • Optionaloptions: HeadCallOptions

        Optional range, SSE-C decryption, response-header overrides, and abort signal.

      Returns Promise<HeadResult>

      Parsed download headers.

    • Hides this file by creating a hide marker at this file name.

      Returns Promise<FileVersion>

      Metadata for the newly created hide marker.

    • Toggles the legal hold flag on a specific file version of this file.

      Legal hold is independent of retention: a file can be on legal hold without any retention policy, and vice versa. The bucket must have Object Lock enabled, and any caller must hold the writeFileLegalHolds capability.

      Parameters

      • fileId: FileId

        The file version to apply the flag to.

      • legalHold: LegalHoldValue

        'on' to apply the hold, 'off' to remove it.

      Returns Promise<UpdateFileLegalHoldResponse>

      Metadata for the updated file version.

    • Sets or updates the Object Lock retention policy on a specific file version of this file.

      The bucket must have Object Lock enabled (fileLockEnabled: true at creation time). Governance-mode retention can be shortened or removed by passing bypassGovernance: true together with an application key that carries the bypassGovernance capability; compliance-mode retention cannot be shortened by anyone until the retainUntilTimestamp elapses.

      Parameters

      • fileId: FileId

        The file version to apply the policy to.

      • retention: FileRetentionValue

        The retention policy to apply.

      • Optionaloptions: { bypassGovernance?: boolean }

        Optional flag for shortening governance-mode retention.

      Returns Promise<UpdateFileRetentionResponse>

      Metadata for the updated file version.