UNPKG

@abstract-filesystem/filesystem

Version:
28 lines (21 loc) 738 B
import { AbstractDriver } from '@abstract-filesystem/types' export type Options = {} export default class MemoryDriver extends AbstractDriver<Options> { public options: Options = {} protected fs = new Map<string, any>() async has(file: string): Promise<boolean> { return this.fs.has(file) } async create(file: string, content: Buffer): Promise<boolean> { if (this.fs.has(file)) throw new Error(`File already exists: ${file}`) this.fs.set(file, content) return true } async remove(file: string): Promise<boolean> { return this.fs.delete(file) } async read(file: string): Promise<Buffer> { if (!this.fs.has(file)) throw new Error(`File not found: ${file}`) return this.fs.get(file) } }