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
Typescript
Module System
Min. Node Version
Node Version
NPM Version
JavaScript (100%)
Love this project? Help keep it running — sponsor us today! 🚀
Total Downloads
9,393,892,928
Last Day
497,445
Last Week
497,445
Last Month
152,178,825
Last Year
2,470,874,960
233 Stars
193 Commits
47 Forks
17 Watching
3 Branches
91 Contributors
Minified
Minified + Gzipped
Latest Version
6.0.0
Package Id
write-file-atomic@6.0.0
Unpacked Size
11.92 kB
Size
4.34 kB
File Count
4
NPM Version
10.8.3
Node Version
22.9.0
Publised On
25 Sept 2024
Cumulative downloads
Total Downloads
Last day
0%
497,445
Compared to previous day
Last week
-98.5%
497,445
Compared to previous week
Last month
-11.1%
152,178,825
Compared to previous month
Last year
11.1%
2,470,874,960
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
license file detected
Details
Reason
0 existing vulnerabilities detected
Reason
SAST tool detected but not run on all commits
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
project is not fuzzed
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Score
Last Scanned on 2025-01-27
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