.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / temp-write / readme.md
1 # temp-write [![Build Status](https://travis-ci.org/sindresorhus/temp-write.svg?branch=master)](https://travis-ci.org/sindresorhus/temp-write)
2
3 > Write string/buffer/stream to a random temp file
4
5
6 ## Install
7
8 ```
9 $ npm install temp-write
10 ```
11
12
13 ## Usage
14
15 ```js
16 const fs = require('fs');
17 const tempWrite = require('temp-write');
18
19 const filepath = tempWrite.sync('unicorn');
20 //=> '/var/folders/_1/tk89k8215ts0rg0kmb096nj80000gn/T/4049f192-43e7-43b2-98d9-094e6760861b'
21
22 fs.readFileSync(filepath, 'utf8');
23 //=> 'unicorn'
24
25
26 tempWrite.sync('unicorn', 'pony.png');
27 //=> '/var/folders/_1/tk89k8215ts0rg0kmb096nj80000gn/T/4049f192-43e7-43b2-98d9-094e6760861b/pony.png'
28
29 tempWrite.sync('unicorn', 'rainbow/cake/pony.png');
30 //=> '/var/folders/_1/tk89k8215ts0rg0kmb096nj80000gn/T/4049f192-43e7-43b2-98d9-094e6760861b/rainbow/cake/pony.png'
31 ```
32
33
34 ## API
35
36 ### tempWrite(input, [filepath])
37
38 Returns a `Promise` for the filepath of the temp file.
39
40 ### tempWrite.sync(input, [filepath])
41
42 Returns the filepath of the temp file.
43
44 #### input
45
46 Type: `string` `Buffer` `stream.Readable`
47
48 Data to write to the temp file. Streams are supported only with the async API.
49
50 #### filepath
51
52 Type: `string`<br>
53 Example: `'img.png'` `'foo/bar/baz.png'`
54
55 Optionally supply a filepath which is appended to the random path.
56
57
58 ## Related
59
60 - [tempy](https://github.com/sindresorhus/tempy) - Get a random temporary file or directory path
61
62
63 ## License
64
65 MIT © [Sindre Sorhus](https://sindresorhus.com)