~webapps/unity-js-scopes/node.js

« back to all changes in this revision

Viewing changes to deps/npm/node_modules/write-file-atomic/README.md

  • Committer: Marcus Tomlinson
  • Date: 2015-11-13 07:59:04 UTC
  • Revision ID: marcus.tomlinson@canonical.com-20151113075904-h0swczmoq1rvstfc
Node v4 (stable)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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**
 
12
  * chown **Object**
 
13
    * uid **Number**
 
14
    * gid **Number**
 
15
  * encoding **String** | **Null** default = 'utf8'
 
16
  * mode **Number** default = 438 (aka 0666 in Octal)
 
17
callback **Function**
 
18
 
 
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.
 
21
 
 
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.
 
27
 
 
28
If provided, the **chown** option requires both **uid** and **gid** properties or else
 
29
you'll get an error.
 
30
 
 
31
The **encoding** option is ignored if **data** is a buffer. It defaults to 'utf8'.
 
32
 
 
33
Example:
 
34
 
 
35
```javascript
 
36
writeFileAtomic('message.txt', 'Hello Node', {chown:{uid:100,gid:50}}, function (err) {
 
37
  if (err) throw err;
 
38
  console.log('It\'s saved!');
 
39
});
 
40
```
 
41
 
 
42
### var writeFileAtomicSync = require('write-file-atomic').sync<br>writeFileAtomicSync(filename, data, [options])
 
43
 
 
44
The synchronous version of **writeFileAtomic**.