.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / write-file-atomic / README.md
1 write-file-atomic
2 -----------------
3
4 This is an extension for node's `fs.writeFile` that makes its operation
5 atomic and allows you set ownership (uid/gid of the file).
6
7 ### var writeFileAtomic = require('write-file-atomic')<br>writeFileAtomic(filename, data, [options], callback)
8
9 * filename **String**
10 * data **String** | **Buffer**
11 * options **Object** | **String**
12   * chown **Object** default, uid & gid of existing file, if any
13     * uid **Number**
14     * gid **Number**
15   * encoding **String** | **Null** default = 'utf8'
16   * fsync **Boolean** default = true
17   * mode **Number** default, from existing file, if any
18   * Promise **Object** default = native Promise object
19 * callback **Function**
20
21 Atomically and asynchronously writes data to a file, replacing the file if it already
22 exists.  data can be a string or a buffer.
23
24 The file is initially named `filename + "." + murmurhex(__filename, process.pid, ++invocations)`.
25 Note that `require('worker_threads').threadId` is used in addition to `process.pid` if running inside of a worker thread.
26 If writeFile completes successfully then, if passed the **chown** option it will change
27 the ownership of the file. Finally it renames the file back to the filename you specified. If
28 it encounters errors at any of these steps it will attempt to unlink the temporary file and then
29 pass the error back to the caller.
30 If multiple writes are concurrently issued to the same file, the write operations are put into a queue and serialized in the order they were called, using Promises. Native promises are used by default, but you can inject your own promise-like object with the **Promise** option. Writes to different files are still executed in parallel.
31
32 If provided, the **chown** option requires both **uid** and **gid** properties or else
33 you'll get an error.  If **chown** is not specified it will default to using
34 the owner of the previous file.  To prevent chown from being ran you can
35 also pass `false`, in which case the file will be created with the current user's credentials.
36
37 If **mode** is not specified, it will default to using the permissions from
38 an existing file, if any.  Expicitly setting this to `false` remove this default, resulting
39 in a file created with the system default permissions.
40
41 If options is a String, it's assumed to be the **encoding** option. The **encoding** option is ignored if **data** is a buffer. It defaults to 'utf8'.
42
43 If the **fsync** option is **false**, writeFile will skip the final fsync call.
44
45 Example:
46
47 ```javascript
48 writeFileAtomic('message.txt', 'Hello Node', {chown:{uid:100,gid:50}}, function (err) {
49   if (err) throw err;
50   console.log('It\'s saved!');
51 });
52 ```
53
54 ### var writeFileAtomicSync = require('write-file-atomic').sync<br>writeFileAtomicSync(filename, data, [options])
55
56 The synchronous version of **writeFileAtomic**.