Gathering detailed insights and metrics for write-file-atomic
Gathering detailed insights and metrics for write-file-atomic
Gathering detailed insights and metrics for write-file-atomic
Gathering detailed insights and metrics for write-file-atomic
Write files in an atomic fashion w/configurable ownership
npm install write-file-atomic
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
230 Stars
193 Commits
47 Forks
17 Watching
3 Branches
90 Contributors
Updated on 25 Sept 2024
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-9.4%
10,423,758
Compared to previous day
Last week
1.4%
61,762,378
Compared to previous week
Last month
16.5%
249,338,158
Compared to previous month
Last year
15.9%
2,498,606,904
Compared to previous year
2
3
This is an extension for node's fs.writeFile
that makes its operation
atomic and allows you set ownership (uid/gid of the file).
writeFileAtomic(filename, data, [options], [callback])
Atomically and asynchronously writes data to a file, replacing the file if it already exists. data can be a string or a buffer.
1var writeFileAtomic = require('write-file-atomic') 2writeFileAtomic(filename, data, [options], [callback])
The file is initially named filename + "." + murmurhex(__filename, process.pid, ++invocations)
.
Note that require('worker_threads').threadId
is used in addition to process.pid
if running inside of a worker thread.
If writeFile completes successfully then, if passed the chown option it will change
the ownership of the file. Finally it renames the file back to the filename you specified. If
it encounters errors at any of these steps it will attempt to unlink the temporary file and then
pass the error back to the caller.
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. Writes to different files are still executed in parallel.
If provided, the chown option requires both uid and gid properties or else
you'll get an error. If chown is not specified it will default to using
the owner of the previous file. To prevent chown from being ran you can
also pass false
, in which case the file will be created with the current user's credentials.
If mode is not specified, it will default to using the permissions from
an existing file, if any. Expicitly setting this to false
remove this default, resulting
in a file created with the system default permissions.
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'.
If the fsync option is false, writeFile will skip the final fsync call.
If the tmpfileCreated option is specified it will be called with the name of the tmpfile when created.
Example:
1writeFileAtomic('message.txt', 'Hello Node', {chown:{uid:100,gid:50}}, function (err) { 2 if (err) throw err; 3 console.log('It\'s saved!'); 4});
This function also supports async/await:
1(async () => { 2 try { 3 await writeFileAtomic('message.txt', 'Hello Node', {chown:{uid:100,gid:50}}); 4 console.log('It\'s saved!'); 5 } catch (err) { 6 console.error(err); 7 process.exit(1); 8 } 9})();
writeFileAtomicSync(filename, data, [options])
The synchronous version of writeFileAtomic.
1var writeFileAtomicSync = require('write-file-atomic').sync 2writeFileAtomicSync(filename, data, [options])
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
all changesets reviewed
Reason
security policy file detected
Details
Reason
no dangerous workflow patterns detected
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
SAST tool detected but not run on all commits
Details
Reason
8 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 6
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
project is not fuzzed
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More