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).
7
### var writeFileAtomic = require('write-file-atomic')<br>writeFileAtomic(filename, data, [options], callback)
10
* data **String** | **Buffer**
15
* encoding **String** | **Null** default = 'utf8'
16
* mode **Number** default = 438 (aka 0666 in Octal)
19
Atomically and asynchronously writes data to a file, replacing the file if it already
20
exists. data can be a string or a buffer.
22
The file is initially named `filename + "." + md5hex(__filename, process.pid, ++invocations)`.
23
If writeFile completes successfully then, if passed the **chown** option it will change
24
the ownership of the file. Finally it renames the file back to the filename you specified. If
25
it encounters errors at any of these steps it will attempt to unlink the temporary file and then
26
pass the error back to the caller.
28
If provided, the **chown** option requires both **uid** and **gid** properties or else
31
The **encoding** option is ignored if **data** is a buffer. It defaults to 'utf8'.
36
writeFileAtomic('message.txt', 'Hello Node', {chown:{uid:100,gid:50}}, function (err) {
38
console.log('It\'s saved!');
42
### var writeFileAtomicSync = require('write-file-atomic').sync<br>writeFileAtomicSync(filename, data, [options])
44
The synchronous version of **writeFileAtomic**.