use fs sync for backwards compatiblity

This commit is contained in:
Flam3rboy 2021-07-10 19:02:24 +02:00
parent 5bfdad897b
commit 3de6cf003e

View File

@ -1,5 +1,5 @@
import { Storage } from "./Storage";
import fs from "fs/promises";
import fs from "fs";
import { join } from "path";
import "missing-native-js-functions";
@ -7,7 +7,7 @@ export class FileStorage implements Storage {
async get(path: string): Promise<Buffer | null> {
path = join(process.env.STORAGE_LOCATION || "", path);
try {
const file = await fs.readFile(path);
const file = fs.readFileSync(path);
// @ts-ignore
return file;
} catch (error) {
@ -18,13 +18,13 @@ export class FileStorage implements Storage {
async set(path: string, value: any) {
path = join(process.env.STORAGE_LOCATION || "", path).replace(/[\\]/g, "/");
const dir = path.split("/").slice(0, -1).join("/");
await fs.mkdir(dir, { recursive: true }).caught();
fs.mkdirSync(dir, { recursive: true });
return fs.writeFile(path, value, { encoding: "binary" });
return fs.writeFileSync(path, value, { encoding: "binary" });
}
async delete(path: string) {
path = join(process.env.STORAGE_LOCATION || "", path);
await fs.unlink(path);
fs.unlinkSync(path);
}
}