safe-file-write
v2.0.0
Published
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.
Downloads
7
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.
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.
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.
try {
import { writeFileSafeSync } from 'write-file-safe';
writeFileSafeSync( '/path/to/file.txt', contents );
console.log( 'FINISHED' );
} catch ( error ) {
error => console.error( error )
}