Cloudflare - v1.3.0
    Preparing search index...

    Class R2Service<E>

    Object-storage capability, backed by R2.

    Bayu Dwiyan Satria

    1.0.0

    1.0.0

    Type Parameters

    Implements

    • ObjectStore<E>
    Index
    • Reads an object as text.

      Parameters

      • env: E

        The Worker environment.

      • key: string

        The object key.

      Returns Promise<string>

      The body, or null when the object does not exist.

    • Reads an object and parses it as JSON.

      Type Parameters

      • T = unknown

      Parameters

      • env: E

        The Worker environment.

      • key: string

        The object key.

      Returns Promise<T>

      The parsed body, or null when the object does not exist.

    • Checks whether an object exists.

      Reads metadata only, so no body is transferred.

      Parameters

      • env: E

        The Worker environment.

      • key: string

        The object key.

      Returns Promise<boolean>

      true when the object exists.

    • Reports whether the bucket is bound to this Worker.

      Parameters

      • env: E

        The Worker environment.

      Returns boolean

      true when the binding is present.

    • Lists the objects under a prefix.

      Parameters

      • env: E

        The Worker environment.

      • prefix: string

        The key prefix to match.

      Returns Promise<StoredObject[]>

      The matched objects.

      One page only — R2 paginates, and a full walk is rarely what a request handler wants.

    • Deletes one or more objects.

      Deleting a key that does not exist is not an error.

      Parameters

      • env: E

        The Worker environment.

      • keys: string | string[]

        A key, or a list of keys.

      Returns Promise<void>

    • Stores an object.

      Parameters

      • env: E

        The Worker environment.

      • key: string

        The object key.

      • body: string | ReadableStream<any> | ArrayBuffer | ArrayBufferView | Blob

        The object body.

      • contentType: string = 'application/octet-stream'

        MIME type recorded on the object.

      Returns Promise<StoredObject>

      The stored object's key and size.

    • Stores a value as JSON.

      Parameters

      • env: E

        The Worker environment.

      • key: string

        The object key.

      • value: unknown

        The value to serialise.

      Returns Promise<StoredObject>

      The stored object's key and size.