MCPcopy
hub / github.com/jvilk/BrowserFS / InMemoryStore

Class InMemoryStore

src/backend/InMemory.ts:7–32  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5 * A simple in-memory key-value store backed by a JavaScript object.
6 */
7export class InMemoryStore implements SyncKeyValueStore, SimpleSyncStore {
8 private store: { [key: string]: Buffer } = {};
9
10 public name() { return InMemoryFileSystem.Name; }
11 public clear() { this.store = {}; }
12
13 public beginTransaction(type: string): SyncKeyValueRWTransaction {
14 return new SimpleSyncRWTransaction(this);
15 }
16
17 public get(key: string): Buffer {
18 return this.store[key];
19 }
20
21 public put(key: string, data: Buffer, overwrite: boolean): boolean {
22 if (!overwrite && this.store.hasOwnProperty(key)) {
23 return false;
24 }
25 this.store[key] = data;
26 return true;
27 }
28
29 public del(key: string): void {
30 delete this.store[key];
31 }
32}
33
34/**
35 * A simple in-memory file system backed by an InMemoryStore.

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected