2019-03-20 19:50:44 +00:00
|
|
|
import * as tmp from 'tmp';
|
|
|
|
|
2022-05-25 07:50:22 +00:00
|
|
|
export function createTemp(): Promise<[string, () => void]> {
|
|
|
|
return new Promise<[string, () => void]>((res, rej) => {
|
2019-03-20 19:50:44 +00:00
|
|
|
tmp.file((e, path, fd, cleanup) => {
|
|
|
|
if (e) return rej(e);
|
|
|
|
res([path, cleanup]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2022-05-25 07:50:22 +00:00
|
|
|
|
|
|
|
export function createTempDir(): Promise<[string, () => void]> {
|
|
|
|
return new Promise<[string, () => void]>((res, rej) => {
|
2022-06-14 14:00:10 +00:00
|
|
|
tmp.dir(
|
|
|
|
{
|
|
|
|
unsafeCleanup: true,
|
|
|
|
},
|
|
|
|
(e, path, cleanup) => {
|
|
|
|
if (e) return rej(e);
|
|
|
|
res([path, cleanup]);
|
2022-12-03 10:42:05 +00:00
|
|
|
},
|
2022-06-14 14:00:10 +00:00
|
|
|
);
|
2022-05-25 07:50:22 +00:00
|
|
|
});
|
|
|
|
}
|