Basic put/get operations with Storage wrapper
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
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
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);
Storage wrapper with Task/Stream semantics for error-tolerant object operations.
-
close(): Task<void, StorageCloseFailed>
Release the connection back to its source (e.g., pool).
-
connect(connector: StorageConnector): Task<Storage, StorageConnectionFailed>
Connect to storage via a connector.
-
delete(key: string): Task<void, StorageDeleteFailed>
Delete an object from storage.
-
get(key: string): Task<StorageObject, StorageGetFailed | StorageObjectNotFound>
Get an object from storage.
-
head(key: string): Task<StorageMetadata, StorageHeadFailed | StorageObjectNotFound>
Get metadata for an object without fetching the body.
-
list(prefix?: string): Source<StorageEntry, StorageListFailed>
List objects in storage with optional prefix.
-
presign(): Task<string, StoragePresignFailed | StoragePresignNotSupported>key: string,options: PresignOptions
Generate a presigned URL for direct object access.
-
put(): Task<void, StoragePutFailed>key: string,body: BodyInput,options?: PutOptions
Put an object into storage.
Error thrown when closing a storage connection fails.
Error thrown when a storage connection cannot be established.
Error thrown when a delete operation fails.
Error thrown when a get operation fails.
Error thrown when a head operation fails.
Error thrown when a list operation fails.
Error thrown when attempting to get or head an object that does not exist.
Error thrown when generating a presigned URL fails.
Error thrown when attempting to use presign on an adapter that does not support presigned URLs.
Error thrown when a put operation fails.
Creates an in-memory storage connector for testing. Data is stored in memory and lost when the process ends.
Extended adapter interface for backends that support presigned URLs.
-
presign(): Promise<string>key: string,options?: PresignOptions
Generate a presigned URL for direct access.
Low-level storage adapter interface. Implement this to create drivers for specific storage backends.
-
close(): Promise<void>
Release the connection back to its source.
-
delete(key: string): Promise<void>
Delete an object from storage.
-
get(key: string): Promise<StorageObject>
Get an object from storage.
-
head(key: string): Promise<StorageMetadata>
Get metadata without fetching the body.
-
list(prefix?: string): AsyncIterable<StorageEntry>
List objects with optional prefix.
-
put(): Promise<void>key: string,body: BodyInput,options?: PutOptions
Put an object into storage.
Connector that produces connected StorageAdapter instances.
-
connect(signal?: AbortSignal): Promise<StorageAdapter>
Acquire a connected adapter.
-
end(): Promise<void>
Close all connections and clean up resources.
Object metadata returned by head operations and included with get results.
Object returned by get operations, containing a body stream and metadata.
Input body types for put operations.