class Storage

Storage wrapper with Task/Stream semantics for error-tolerant object operations.

Examples

Basic put/get operations

import { Storage, createMemory } from "@anabranch/storage";

const connector = createMemory();
const storage = await Storage.connect(connector).run();

await storage.put("hello.txt", "Hello, World!").run();
const object = await storage.get("hello.txt").run();

Stream listing objects

const { successes, errors } = await storage.list("users/")
  .withConcurrency(5)
  .map(async (entry) => await processEntry(entry))
  .tapErr((err) => console.error("Failed:", err))
  .partition();

With retry and timeout

await storage.put("important.txt", data)
  .retry({ attempts: 3, delay: (attempt) => 100 * Math.pow(2, attempt) })
  .timeout(30_000)
  .run();

Constructors

new
Storage(adapter: StorageAdapter)

Static Methods

Connect to storage via a connector.

Methods

Release the connection back to its source (e.g., pool).

delete(key: string): Task<void, StorageDeleteFailed>

Delete an object from storage.

Get an object from storage.

Get metadata for an object without fetching the body.

list(prefix?: string): Source<StorageEntry, StorageListFailed>

List objects in storage with optional prefix.

Generate a presigned URL for direct object access.

Only available on adapters that implement PresignableAdapter (S3, GCS). Throws StoragePresignNotSupported for adapters that don't support presigning (memory, browser).

put(
key: string,
body: BodyInput,
options?: PutOptions,
): Task<void, StoragePutFailed>

Put an object into storage.