# fs-write-stream-atomic

> Like `fs.createWriteStream(...)`, but atomic.

Latest version **1.0.10** (published 2017-03-07) · ISC license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install fs-write-stream-atomic
pnpm add fs-write-stream-atomic
yarn add fs-write-stream-atomic
bun add fs-write-stream-atomic
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.0.10 |
| Published | 2017-03-07 |
| First published | 2014-09-19 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 49 |
| Author | Isaac Z. Schlueter |
| Maintainers | iarna, isaacs, othiym23, zkat |

## Links

- npm: https://www.npmjs.com/package/fs-write-stream-atomic
- Repository: https://github.com/npm/fs-write-stream-atomic
- Issues: https://github.com/npm/fs-write-stream-atomic/issues
- npm.io page: https://npm.io/package/fs-write-stream-atomic

## Dependencies (4)

- [iferr](https://npm.io/package/iferr.md) ^0.1.5
- [graceful-fs](https://npm.io/package/graceful-fs.md) ^4.1.2
- [imurmurhash](https://npm.io/package/imurmurhash.md) ^0.1.4
- [readable-stream](https://npm.io/package/readable-stream.md) 1 || 2

## Recent versions

- 1.0.10 (latest) — 2017-03-07
- 1.0.9 — 2017-03-07
- 1.0.8 — 2015-12-12
- 1.0.7 — 2015-12-10
- 1.0.6 — 2015-12-10
- 1.0.5 — 2015-12-02
- 1.0.4 — 2015-09-09
- 1.0.3 — 2015-05-21
- 1.0.2 — 2014-09-29
- 1.0.1 — 2014-09-22
- 1.0.0 — 2014-09-19

## README

# fs-write-stream-atomic

Like `fs.createWriteStream(...)`, but atomic.

Writes to a tmp file and does an atomic `fs.rename` to move it into
place when it's done.

First rule of debugging: **It's always a race condition.**

## USAGE

```javascript
var fsWriteStreamAtomic = require('fs-write-stream-atomic')
// options are optional.
var write = fsWriteStreamAtomic('output.txt', options)
var read = fs.createReadStream('input.txt')
read.pipe(write)

// When the write stream emits a 'finish' or 'close' event,
// you can be sure that it is moved into place, and contains
// all the bytes that were written to it, even if something else
// was writing to `output.txt` at the same time.
```

### `fsWriteStreamAtomic(filename, [options])`

* `filename` {String} The file we want to write to
* `options` {Object}
  * `chown` {Object} User and group to set ownership after write
    * `uid` {Number}
    * `gid` {Number}
  * `encoding` {String} default = 'utf8'
  * `mode` {Number} default = `0666`
  * `flags` {String} default = `'w'`

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