ligo/tools/webide/packages/server/src/storage/disk-storage.ts
Jev Björsell c119c44c13
Import webide into main ligo monorepo
When this is merged https://gitlab.com/ligolang/ligo-web-ide/ will be
marked as deprecated.

This MR does not hook up the webide build to the main CI. The CI
integration will come in a subsequent MR for the sake of making review
easier.
2020-02-06 19:04:18 -08:00

24 lines
638 B
TypeScript

import fs from 'fs';
import { join } from 'path';
import { FileStorage, FileNotFoundError } from './interface';
export class DiskStorage implements FileStorage {
constructor(private readonly directory: string) {}
async write(filename: string, content: string) {
const path = join(this.directory, filename);
return fs.writeFileSync(path, content);
}
async read(filename: string): Promise<string> {
const path = join(this.directory, filename);
if (!fs.existsSync(path)) {
throw new FileNotFoundError(`File not found ${path}`);
}
const buf = fs.readFileSync(path);
return buf.toString();
}
}