# atomic-file-rw

Latest version **0.3.0** (published 2022-05-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install atomic-file-rw
pnpm add atomic-file-rw
yarn add atomic-file-rw
bun add atomic-file-rw
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.0 |
| Published | 2022-05-01 |
| First published | 2021-04-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 14 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6 |
| Author | Anders Rune Jensen |
| Maintainers | arj03 |

## Links

- npm: https://www.npmjs.com/package/atomic-file-rw
- Repository: https://github.com/ssb-ngi-pointer/atomic-file-rw
- Issues: https://github.com/ssb-ngi-pointer/atomic-file-rw/issues
- npm.io page: https://npm.io/package/atomic-file-rw

## Dependencies (2)

- [mutexify](https://npm.io/package/mutexify.md) ^1.3.1
- [idb-kv-store](https://npm.io/package/idb-kv-store.md) ^4.5.0

## Recent versions

- 0.3.0 (latest) — 2022-05-01
- 0.2.2 — 2021-05-01
- 0.2.1 — 2021-04-19
- 0.2.0 — 2021-04-18
- 0.1.0 — 2021-04-16

## README

<!--
SPDX-FileCopyrightText: 2021 Anders Rune Jensen

SPDX-License-Identifier: CC0-1.0
-->

# Atomic-file-rw

This module is meant as a replacement for
[atomic-file](https://github.com/flumedb/atomic-file) as it has better
error handling on node and is faster in the browser.

The library is written to handle writing to a few number of files in a
safe manner. Concurrent writes to the same file are completed in the
order they are started. A temporary file with the same filename as the
original — with a suffix `~` — is employed to ensure atomicity.

## Example

Write a buffer to file and read it again:

```js
const atomic = require('atomic-file-rw')

atomic.writeFile("test.txt", Buffer.from('GREETINGS'), (err, x) => {
  atomic.readFile("test.txt", (err, buf) => {
    console.log(buf.toString())
  })
})
```

## API

### `atomic.readFile(path[, options], callback)`

Same arguments as Node.js's `fs.readFile`, but in the browser the
`options` is ignored.

### `atomic.writeFile(file, data[, options], callback)`

Same arguments as Node.js's `fs.writeFile`, but in the browser the
`options` is ignored.

### `atomic.deleteFile(file, callback)`

Same arguments as Node.js's `fs.unlink`.

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