server/utils/temp.ts

21 lines
655 B
TypeScript
Raw Normal View History

2024-04-07 07:30:49 +02:00
import { exists, mkdir, readFile, writeFile } from "node:fs/promises";
import { join } from "node:path";
export const writeToTempDirectory = async (filename: string, data: string) => {
2024-04-07 07:30:49 +02:00
const tempDir = join("/tmp/", "lysand");
if (!(await exists(tempDir))) await mkdir(tempDir);
2024-04-07 07:30:49 +02:00
const tempFile = join(tempDir, filename);
await writeFile(tempFile, data);
2024-04-07 07:30:49 +02:00
return tempFile;
};
export const readFromTempDirectory = async (filename: string) => {
2024-04-07 07:30:49 +02:00
const tempDir = join("/tmp/", "lysand");
if (!(await exists(tempDir))) await mkdir(tempDir);
2024-04-07 07:30:49 +02:00
const tempFile = join(tempDir, filename);
return readFile(tempFile, "utf-8");
};