2023-12-06 23:10:22 +01:00
|
|
|
import { join } from "path";
|
|
|
|
|
import { exists, mkdir, writeFile, readFile } from "fs/promises";
|
|
|
|
|
|
|
|
|
|
export const writeToTempDirectory = async (filename: string, data: string) => {
|
2023-12-06 23:10:43 +01:00
|
|
|
const tempDir = join("/tmp/", "lysand");
|
2023-12-06 23:10:22 +01:00
|
|
|
if (!(await exists(tempDir))) await mkdir(tempDir);
|
|
|
|
|
|
|
|
|
|
const tempFile = join(tempDir, filename);
|
|
|
|
|
await writeFile(tempFile, data);
|
|
|
|
|
|
|
|
|
|
return tempFile;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const readFromTempDirectory = async (filename: string) => {
|
2023-12-06 23:10:43 +01:00
|
|
|
const tempDir = join("/tmp/", "lysand");
|
2023-12-06 23:10:22 +01:00
|
|
|
if (!(await exists(tempDir))) await mkdir(tempDir);
|
|
|
|
|
|
|
|
|
|
const tempFile = join(tempDir, filename);
|
|
|
|
|
return readFile(tempFile, "utf-8");
|
|
|
|
|
};
|