default

Examples

Basic put/get operations with Storage wrapper

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

const connector = createInMemory({ prefix: "files/" });
const storage = await Storage.connect(connector).run();

await storage.put("hello.txt", "Hello, World!").run();
const object = await storage.get("hello.txt").run();
console.log(await new Response(object.body).text());

Stream listing with concurrent processing

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

await storage.put("users/1.json", '{"name": "Alice"}');
await storage.put("users/2.json", '{"name": "Bob"}');

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

Head request for metadata

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

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

await storage.put("image.png", imageBytes, { contentType: "image/png" }).run();
const metadata = await storage.head("image.png").run();
console.log(metadata.contentType, metadata.size);

With retry and timeout

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

Classes

c
StorageCloseFailed(
message: string,
cause?: unknown
)

Error thrown when closing a storage connection fails.

c
StorageConnectionFailed(
message: string,
cause?: unknown
)

Error thrown when a storage connection cannot be established.

c
StorageObjectNotFound(key: string)

Error thrown when attempting to get or head an object that does not exist.

c
c
StoragePresignNotSupported()

Error thrown when attempting to use presign on an adapter that does not support presigned URLs.

Functions

f
createInMemory(options?: StorageOptions): StorageConnector

Creates an in-memory storage connector for testing. Data is stored in memory and lost when the process ends.

Interfaces

I
PresignableAdapter

Extended adapter interface for backends that support presigned URLs.

I
StorageAdapter

Low-level storage adapter interface. Implement this to create drivers for specific storage backends.

I
StorageConnector

Connector that produces connected StorageAdapter instances.

I
StorageObject

Object returned by get operations, containing a body stream and metadata.

I
StorageOptions

Storage configuration options.

Type Aliases

T
BodyInput = Uint8Array | ReadableStream | string

Input body types for put operations.