Interface R2Bucket

All Superinterfaces:
org.teavm.jso.JSObject

public interface R2Bucket extends org.teavm.jso.JSObject
An R2 bucket. Declared with r2(), named BLOB by default.

Strongly consistent, unlike KV: a read after a write returns the value that was written.

 R2Bucket blob = env.r2();
 blob.put("greeting.txt", "hello world!");
 String greeting = blob.getText("greeting.txt");
Since:
1.0.0
  • Method Details

    • get

      default R2Bucket.R2ObjectBody get(String key)
      Reads an object.
      Parameters:
      key - the key
      Returns:
      the object, or null when the key is absent
    • getText

      default String getText(String key)
      Reads an object's body as text.
      Parameters:
      key - the key
      Returns:
      the body, or null when the key is absent
    • getBytes

      default org.teavm.jso.typedarrays.ArrayBuffer getBytes(String key)
      Reads an object's body as bytes.
      Parameters:
      key - the key
      Returns:
      the body, or null when the key is absent
    • getRange

      default R2Bucket.R2ObjectBody getRange(String key, int offset, int length)
      Reads part of an object.
      Parameters:
      key - the key
      offset - where to start
      length - how many bytes to read
      Returns:
      the object, or null when the key is absent
    • head

      default R2Bucket.R2Object head(String key)
      Reads an object's metadata without its body.
      Parameters:
      key - the key
      Returns:
      the metadata, or null when the key is absent
    • put

      default R2Bucket.R2Object put(String key, String value)
      Writes text.
      Parameters:
      key - the key
      value - the body
      Returns:
      what was written
    • put

      default R2Bucket.R2Object put(String key, String value, String contentType)
      Writes text with a content type.
      Parameters:
      key - the key
      value - the body
      contentType - the media type to serve it as
      Returns:
      what was written
    • putBytes

      default R2Bucket.R2Object putBytes(String key, org.teavm.jso.typedarrays.ArrayBuffer value)
      Writes bytes.
      Parameters:
      key - the key
      value - the body
      Returns:
      what was written
    • putBytes

      default R2Bucket.R2Object putBytes(String key, byte[] value)
      Writes bytes.
      Parameters:
      key - the key
      value - the body
      Returns:
      what was written
    • putBytes

      default R2Bucket.R2Object putBytes(String key, org.teavm.jso.typedarrays.ArrayBuffer value, String contentType, TSObject metadata)
      Writes bytes with a content type and custom metadata.
      Parameters:
      key - the key
      value - the body
      contentType - the media type, or null
      metadata - custom metadata, or null
      Returns:
      what was written
    • delete

      default void delete(String key)
      Removes an object. Succeeds whether or not it was present.
      Parameters:
      key - the key
    • delete

      default void delete(String... keys)
      Removes several objects in one call.
      Parameters:
      keys - the keys
    • list

      default R2Bucket.R2Objects list()
      Returns the first page of objects.
      Returns:
      the first page of objects
    • list

      default R2Bucket.R2Objects list(String prefix)
      Lists objects under a prefix.
      Parameters:
      prefix - the prefix
      Returns:
      the first page of matching objects
    • list

      default R2Bucket.R2Objects list(String prefix, String cursor, int limit)
      Lists objects from where a previous page left off.
      Parameters:
      prefix - the prefix, or null for everything
      cursor - R2Bucket.R2Objects.getCursor() from the previous page
      limit - how many to return, at most 1000
      Returns:
      the next page
    • listAll

      default List<String> listAll(String prefix)
      Returns every key under a prefix, following the cursor until the listing completes.
      Returns:
      every key under a prefix, following the cursor until the listing completes
    • getObject

      org.teavm.jso.core.JSPromise<R2Bucket.R2ObjectBody> getObject(String key)
    • getObject

      org.teavm.jso.core.JSPromise<R2Bucket.R2ObjectBody> getObject(String key, org.teavm.jso.JSObject options)
    • headObject

      org.teavm.jso.core.JSPromise<R2Bucket.R2Object> headObject(String key)
    • putText

      org.teavm.jso.core.JSPromise<R2Bucket.R2Object> putText(String key, String value)
    • putText

      org.teavm.jso.core.JSPromise<R2Bucket.R2Object> putText(String key, String value, org.teavm.jso.JSObject options)
    • putBuffer

      org.teavm.jso.core.JSPromise<R2Bucket.R2Object> putBuffer(String key, org.teavm.jso.typedarrays.ArrayBuffer value)
    • putBuffer

      org.teavm.jso.core.JSPromise<R2Bucket.R2Object> putBuffer(String key, org.teavm.jso.typedarrays.ArrayBuffer value, org.teavm.jso.JSObject options)
    • deleteObject

      org.teavm.jso.core.JSPromise<org.teavm.jso.JSObject> deleteObject(String key)
    • deleteObjects

      org.teavm.jso.core.JSPromise<org.teavm.jso.JSObject> deleteObjects(org.teavm.jso.core.JSArray<org.teavm.jso.core.JSString> keys)
    • listObjects

      org.teavm.jso.core.JSPromise<R2Bucket.R2Objects> listObjects(org.teavm.jso.JSObject options)