https://github.com/jamiebuilds/write-files-atomic
Write many files atomically
https://github.com/jamiebuilds/write-files-atomic
atomic files fs nodejs
Last synced: over 1 year ago
JSON representation
Write many files atomically
- Host: GitHub
- URL: https://github.com/jamiebuilds/write-files-atomic
- Owner: jamiebuilds
- License: mit
- Created: 2018-07-24T01:33:11.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-09-11T17:58:42.000Z (almost 8 years ago)
- Last Synced: 2025-03-12T21:02:55.138Z (over 1 year ago)
- Topics: atomic, files, fs, nodejs
- Language: JavaScript
- Size: 33.2 KB
- Stars: 121
- Watchers: 2
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# write-files-atomic
> Write many files atomically
- Creates temporary files with file contents
- Moves them all at once using `rename()`
- Automatically cleans up after itself
- Optimized to be as fast as possible
- Doesn't break file watchers
- Doesn't swallow errors
- Includes Flow types
## Install
```
yarn add write-files-atomic
```
## Usage
```js
const writeFilesAtomic = require('write-files-atomic');
await writeFilesAtomic([
{ filePath: './foo.txt', fileContents: '...foo...' },
{ filePath: './bar.txt', fileContents: '...bar...' },
{ filePath: './baz.txt', fileContents: '...baz...' },
]);
```
## API
```ts
type Files = Array<{
filePath: string,
fileContents: string | Buffer,
encoding?: string, // default 'utf8'
mode?: number,
chown?: { uid: number, gid: number }, // default `fs.stat` of existing file
}>;
declare function writeFilesAtomic(files: Files): Promise;
```