etcher/lib/shared/tmp.ts
Alexis Svinartchouk 512785e0a9 Remove bluebird from main process, reduce lodash usage
Changelog-entry: Remove bluebird from main process, reduce lodash usage
Change-type: patch
2020-07-20 11:11:41 +02:00

25 lines
581 B
TypeScript

import * as Bluebird from 'bluebird';
import * as tmp from 'tmp';
function tmpFileAsync(
options: tmp.FileOptions,
): Promise<{ path: string; cleanup: () => void }> {
return new Promise((resolve, reject) => {
tmp.file(options, (error, path, _fd, cleanup) => {
if (error) {
reject(error);
} else {
resolve({ path, cleanup });
}
});
});
}
export function tmpFileDisposer(
options: tmp.FileOptions,
): Bluebird.Disposer<{ path: string; cleanup: () => void }> {
return Bluebird.resolve(tmpFileAsync(options)).disposer(({ cleanup }) => {
cleanup();
});
}