hippofish/packages/backend/src/misc/create-temp.ts

25 lines
519 B
TypeScript
Raw Normal View History

2023-01-13 05:40:33 +01:00
import * as tmp from "tmp";
export function createTemp(): Promise<[string, () => void]> {
return new Promise<[string, () => void]>((res, rej) => {
tmp.file((e, path, fd, cleanup) => {
if (e) return rej(e);
res([path, cleanup]);
});
});
}
export function createTempDir(): Promise<[string, () => void]> {
return new Promise<[string, () => void]>((res, rej) => {
tmp.dir(
{
unsafeCleanup: true,
},
(e, path, cleanup) => {
if (e) return rej(e);
res([path, cleanup]);
2023-01-13 05:40:33 +01:00
},
);
});
}