with-temp-file

1.0.6 • Public • Published

with-temp-file

Build Status Coverage Status

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)
}

Readme

Keywords

none

Package Sidebar

Install

npm i with-temp-file

Weekly Downloads

4

Version

1.0.6

License

MIT

Unpacked Size

7.89 kB

Total Files

9

Last publish

Collaborators

  • fabiosantoscode