| 5 | * A simple in-memory key-value store backed by a JavaScript object. |
| 6 | */ |
| 7 | export 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. |
nothing calls this directly
no outgoing calls
no test coverage detected