with-temp-file
v1.0.6
Published
Call a function with a temporary file, and clean up when the function returns!
Downloads
12
Readme
with-temp-file
Call a function with a temporary file, and clean up when the function returns!
usage
Call withTempFile with a function that takes the writeStream and optionally your own temporary file name. It will be called. It can return a promise or call the callback which is the third argument of the function.
const withTempFile = require('with-temp-file')
async function main () {
const result = await withTempFile((ws, filename) => {
ws.write(fileContents())
ws.end()
return fs.readFileSync(filename) + ''
})
console.log(result)
const result2 = await withTempFile((ws, filename, cb) => {
ws.write(fileContents2())
ws.end()
cb()
}, __dirname + '/.' + Math.random())
console.log(result2)
}