# 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.

Latest version **2.0.0** (published 2019-04-24) · ISC license · 0 weekly downloads

## Install

```sh
npm install safe-file-write
pnpm add safe-file-write
yarn add safe-file-write
bun add safe-file-write
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2019-04-24 |
| First published | 2017-05-16 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 15.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Pedro M. Silva |
| Maintainers | pedromsilva |
| Keywords | fs, write, files, safe |

## Links

- npm: https://www.npmjs.com/package/safe-file-write
- Repository: https://github.com/scorchpt/safe-file-write
- Homepage: https://github.com/scorchpt/safe-file-write#readme
- Issues: https://github.com/scorchpt/safe-file-write/issues
- npm.io page: https://npm.io/package/safe-file-write

## Dependencies (3)

- [mkdirp](https://npm.io/package/mkdirp.md) ^0.5.1
- [is-there](https://npm.io/package/is-there.md) ^4.4.2
- [fs-promise](https://npm.io/package/fs-promise.md) ^2.0.3

## Alternatives

- [unionfs](https://npm.io/package/unionfs.md) — 2.2M weekly downloads
- [path-starts-with](https://npm.io/package/path-starts-with.md) — 35.9K weekly downloads
- [redzip](https://npm.io/package/redzip.md) — 1.2K weekly downloads
- [vscode-anymatch](https://npm.io/package/vscode-anymatch.md) — 848 weekly downloads
- [@ledgerhq/coin-filecoin](https://npm.io/package/@ledgerhq/coin-filecoin.md) — 793 weekly downloads

## Recent versions

- 2.0.0 (latest) — 2019-04-24
- 1.1.0 — 2017-07-25
- 1.0.1 — 2017-05-16
- 1.0.0 — 2017-05-16

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

---
_Source: https://npm.io/package/safe-file-write · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
