Skip to content

best way to save what you love

lib/storage: add abstract storage class

jjdd507e1dcd9b
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<AbstractStorage> {
+ throw "init() call on abstract implementation";
+ }
+
+ static isAvailable(): boolean {
+ return false;
+ }
+
+ abstract res(): Promise<File>;
+ abstract read(size: number, offset: number): Uint8Array;
+ abstract write(data: Uint8Array | Int8Array, offset: number): Promise<number>;
+ abstract destroy(): Promise<void>;
+};
+