Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pedromsilvapt/safe-file-write
Write to a file, making sure it's parent folders exist, and that if the write operation is cancelled mid-writing, it does not corrupt any possible file there previously.
https://github.com/pedromsilvapt/safe-file-write
Last synced: 11 days ago
JSON representation
Write to a file, making sure it's parent folders exist, and that if the write operation is cancelled mid-writing, it does not corrupt any possible file there previously.
- Host: GitHub
- URL: https://github.com/pedromsilvapt/safe-file-write
- Owner: pedromsilvapt
- Created: 2017-05-16T15:12:56.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-04-24T18:51:58.000Z (over 5 years ago)
- Last Synced: 2024-09-15T21:27:56.296Z (4 months ago)
- Language: TypeScript
- Size: 5.86 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# safe-file-write
> Write to a file, making sure it's parent folders exist, and that if the write operation is cancelled mid-writing, it does not corrupt any possible file there previously.
# Installation
You can install this package globally, so that it is accessible everywhere in your system.```shell
npm install --save safe-file-write
```# Usage
Just import the module and call the function. Ir returns a function the resolves when the writing has finished.```typescript
import writeFileSafe from 'write-file-safe';writeFileSafe( '/path/to/file.txt', contents )
.then( () => console.log( 'FINISHED' ) )
.catch( error => console.error( error ) );
```There is also a synchronous version.
```typescript
try {
import { writeFileSafeSync } from 'write-file-safe';
writeFileSafeSync( '/path/to/file.txt', contents );console.log( 'FINISHED' );
} catch ( error ) {
error => console.error( error )
}
```