ssb-ngi-pointer / atomic-file-rw-archived

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

⚠️ This repo was moved to https://github.com/ssbc/atomic-file-rw. This archival will remain in this GitHub org ssb-ngi-pointer to demonstrate the outcome of the work done by the SSB NGI Pointer team during 2020 and 2021. The SSB NGI Pointer team is no longer active because we completed our grant project.

Atomic-file-rw

This module is meant as a replacement for 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:

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.

About


Languages

Language:JavaScript 95.3%Language:HTML 4.7%