c2370a1be6
* chore: Add the SPDX information to each file Add copyright and licensing information as defined in version 3.0 of the REUSE Specification. * tweak format --------- Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
29 lines
736 B
TypeScript
29 lines
736 B
TypeScript
/*
|
|
* SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
|
|
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, process.env.NODE_ENV === 'production' ? 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, process.env.NODE_ENV === 'production' ? cleanup : () => {}]);
|
|
},
|
|
);
|
|
});
|
|
}
|