2024-04-07 07:30:49 +02:00
|
|
|
import { exists, mkdir, readFile, writeFile } from "node:fs/promises";
|
|
|
|
|
import { join } from "node:path";
|
2023-12-06 23:10:22 +01:00
|
|
|
|
|
|
|
|
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);
|
2023-12-06 23:10:22 +01:00
|
|
|
|
2024-04-07 07:30:49 +02:00
|
|
|
const tempFile = join(tempDir, filename);
|
|
|
|
|
await writeFile(tempFile, data);
|
2023-12-06 23:10:22 +01:00
|
|
|
|
2024-04-07 07:30:49 +02:00
|
|
|
return tempFile;
|
2023-12-06 23:10:22 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
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);
|
2023-12-06 23:10:22 +01:00
|
|
|
|
2024-04-07 07:30:49 +02:00
|
|
|
const tempFile = join(tempDir, filename);
|
|
|
|
|
return readFile(tempFile, "utf-8");
|
2023-12-06 23:10:22 +01:00
|
|
|
};
|