safe-file-write
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

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 )
}

Readme

Keywords

Package Sidebar

Install

npm i safe-file-write

Weekly Downloads

2

Version

2.0.0

License

ISC

Unpacked Size

15.4 kB

Total Files

7

Last publish

Collaborators

  • pedromsilva