fast-write-atomic

Fast way to write a file atomically, for Node.js

MIT 5 个版本
安装
npm install fast-write-atomic
yarn add fast-write-atomic
pnpm add fast-write-atomic
bun add fast-write-atomic
README

fast-write-atomic

CI npm version

Fast way to write a file atomically, for Node.js.

Requirements

  • Node.js 20+

Install

npm i fast-write-atomic

Example

const writeFile = require('fast-write-atomic')

const data = Buffer.from('hello world')

writeFile('./hello', data, function (err) {
  if (err) {
    console.log(err)
    return
  }

  console.log('file written')
})

Promise API

writeFile.promise(path, content) returns a Promise and keeps the same atomicity behavior.

const writeFile = require('fast-write-atomic')

await writeFile.promise('./hello', Buffer.from('hello world'))

Development

npm install
npm test
npm run cov
node bench.js

Benchmarks

Those benchmarks write a 1 MB file a thousand times:

benchWriteFileAtomic*1000: 9830.501ms
benchFastWriteAtomic*1000: 8848.916ms
benchWriteFileAtomic*1000: 9944.722ms
benchFastWriteAtomic*1000: 8997.108ms

License

MIT

版本列表
0.4.0 2026-02-13
0.2.1 2019-03-08
0.2.0 2019-01-04
0.1.1 2018-12-21
0.1.0 2018-12-20