24 lines
670 B
TypeScript
24 lines
670 B
TypeScript
import type { DriveLike } from "@suaveplan/vault";
|
|
|
|
/** Minimal in-memory `DriveLike` for tests. */
|
|
export function createMemoryDrive(): DriveLike {
|
|
const store = new Map<string, Uint8Array>();
|
|
return {
|
|
async read(path) {
|
|
const bytes = store.get(path);
|
|
if (bytes === undefined)
|
|
throw new Error(`memory-drive: missing path ${path}`);
|
|
return bytes;
|
|
},
|
|
async write(path, data) {
|
|
store.set(path, data);
|
|
},
|
|
async delete(path) {
|
|
return store.delete(path);
|
|
},
|
|
async exists(path) {
|
|
return store.has(path);
|
|
},
|
|
};
|
|
}
|