import * as tmp from 'tmp' ; import { fs } from './fs' ; export async function withTempFile < T > ( content , fileType , fn ) { const tempFile = tmp . fileSync ( { prefix : "vskind-" , postfix : `.${ fileType }` } ) ; await fs . writeFile ( tempFile . name , content ) ; try { return fn ( tempFile . name ) ; } finally { tempFile . removeCallback ( ) ; } } export async function withOptionalTempFile < T > ( content , fileType , fn ) { if ( ! content ) { return fn ( undefined ) ; } const tempFile = tmp . fileSync ( { prefix : "vskind-" , postfix : `.${ fileType }` } ) ; await fs . writeFile ( tempFile . name , content ) ; try { return await fn ( tempFile . name ) ; } finally { tempFile . removeCallback ( ) ; } }