From dd507e1dcd9b16414bc02a76fd419db11d2d6b09 Mon Sep 17 00:00:00 2001 From: jj Date: Wed, 30 Apr 2025 17:21:22 +0000 Subject: [PATCH] lib/storage: add abstract storage class --- web/src/lib/storage/opfs.ts | 5 ++++- web/src/lib/storage/storage.ts | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 web/src/lib/storage/storage.ts diff --git a/web/src/lib/storage/opfs.ts b/web/src/lib/storage/opfs.ts index 092fc851..e038db30 100644 --- a/web/src/lib/storage/opfs.ts +++ b/web/src/lib/storage/opfs.ts @@ -1,11 +1,14 @@ +import { AbstractStorage } from "./storage"; + const COBALT_PROCESSING_DIR = "cobalt-processing-data"; -export class OPFSStorage { +export class OPFSStorage extends AbstractStorage { #root; #handle; #io; constructor(root: FileSystemDirectoryHandle, handle: FileSystemFileHandle, reader: FileSystemSyncAccessHandle) { + super(); this.#root = root; this.#handle = handle; this.#io = reader; diff --git a/web/src/lib/storage/storage.ts b/web/src/lib/storage/storage.ts new file mode 100644 index 00000000..d9d6381e --- /dev/null +++ b/web/src/lib/storage/storage.ts @@ -0,0 +1,15 @@ +export abstract class AbstractStorage { + static init(): Promise { + throw "init() call on abstract implementation"; + } + + static isAvailable(): boolean { + return false; + } + + abstract res(): Promise; + abstract read(size: number, offset: number): Uint8Array; + abstract write(data: Uint8Array | Int8Array, offset: number): Promise; + abstract destroy(): Promise; +}; +