# output-file-atomically

> Write a file in an atomic fashion and create its ancestor directories if needed.

Latest version **1.0.0** (published 2017-04-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install output-file-atomically
pnpm add output-file-atomically
yarn add output-file-atomically
bun add output-file-atomically
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2017-04-12 |
| First published | 2017-04-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=4 |
| Dependencies | 3 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | linusu |
| Keywords | async, asynchronous, asynchronously, atomic, atomically, create, file, files, fs, mkdir, mkdirp, output, promise, promises, then, write, writeFile |

## Links

- npm: https://www.npmjs.com/package/output-file-atomically
- Repository: https://github.com/linusu/node-output-file-atomically
- Homepage: https://github.com/linusu/node-output-file-atomically#readme
- Issues: https://github.com/linusu/node-output-file-atomically/issues
- npm.io page: https://npm.io/package/output-file-atomically

## Dependencies (3)

- [pify](https://npm.io/package/pify.md) ^2.3.0
- [mkdirp](https://npm.io/package/mkdirp.md) ^0.5.1
- [write-file-atomic](https://npm.io/package/write-file-atomic.md) ^1.3.1

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

- 1.0.0 (latest) — 2017-04-12

## README

# Output File Atomically

Write a file in an atomic fashion and create its ancestor directories if needed.

## Installation

```sh
npm install --save output-file-atomically
```

## Usage

```js
const outputFileAtomically = require('output-file-atomically')

outputFileAtomically('path/to/file.txt', 'Hello, World!')
  .then(() => console.log('File created!'))
```

## API

### `outputFileAtomically(filename, data[, options]) => Promise`

* filename **String**
* data **String** | **Buffer**
* options **Object**
  * chown **Object**
    * uid **Number**
    * gid **Number**
  * encoding **String** | **Null** default = 'utf8'
  * mode **Number** default = 438 (aka 0666 in Octal)

Atomically and asynchronously writes `data` to a file, replacing the file if it already exists. `data` can be a string or a buffer.

The file is initially named `filename + "." + murmurhex(__filename, process.pid, ++invocations)`. If `writeFile` completes successfully then, if passed the **chown** option it will change the ownership of the file. Finally it renames the file back to the filename you specified. If it encounters errors at any of these steps it will attempt to unlink the temporary file and then reject the returned promise.

If provided, the **chown** option requires both **uid** and **gid** properties or else the returned promise will be rejected with an error.

The **encoding** option is ignored if **data** is a buffer. It defaults to `'utf8'`.

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