1 # temp-write [![Build Status](https://travis-ci.org/sindresorhus/temp-write.svg?branch=master)](https://travis-ci.org/sindresorhus/temp-write)
3 > Write string/buffer/stream to a random temp file
9 $ npm install temp-write
16 const fs = require('fs');
17 const tempWrite = require('temp-write');
19 const filepath = tempWrite.sync('unicorn');
20 //=> '/var/folders/_1/tk89k8215ts0rg0kmb096nj80000gn/T/4049f192-43e7-43b2-98d9-094e6760861b'
22 fs.readFileSync(filepath, 'utf8');
26 tempWrite.sync('unicorn', 'pony.png');
27 //=> '/var/folders/_1/tk89k8215ts0rg0kmb096nj80000gn/T/4049f192-43e7-43b2-98d9-094e6760861b/pony.png'
29 tempWrite.sync('unicorn', 'rainbow/cake/pony.png');
30 //=> '/var/folders/_1/tk89k8215ts0rg0kmb096nj80000gn/T/4049f192-43e7-43b2-98d9-094e6760861b/rainbow/cake/pony.png'
36 ### tempWrite(input, [filepath])
38 Returns a `Promise` for the filepath of the temp file.
40 ### tempWrite.sync(input, [filepath])
42 Returns the filepath of the temp file.
46 Type: `string` `Buffer` `stream.Readable`
48 Data to write to the temp file. Streams are supported only with the async API.
53 Example: `'img.png'` `'foo/bar/baz.png'`
55 Optionally supply a filepath which is appended to the random path.
60 - [tempy](https://github.com/sindresorhus/tempy) - Get a random temporary file or directory path
65 MIT © [Sindre Sorhus](https://sindresorhus.com)