This package has been deprecated

Author message:

Please use write-file-atomic instead

clean-write

0.0.1 • Public • Published

Codecov Travis Node Gitter Twitter Medium

Cleanup corrupted files on write errors.

When an exception is thrown while a file is being written, that file will be corrupted. The same problem occurs when the process exits unexpectedly (for example with CTRL-C).

This library removes corrupted files in such cases.

Example

const cleanWrite = require('clean-write')
 
const { writeFile } = require('fs')
const { promisify } = require('util')
const writeFileAsync = promisify(writeFile)
 
const filePath = './path/to/file.js'
const writeFunction = async function() {
  await writeFileAsync(filePath, 'example')
}
 
// If an exception happens or if the program exits, the file will be removed
await cleanWrite(writeFunction, filePath)

Install

npm install clean-write

Usage

cleanWrite(writeFunction, filePath)

writeFunction: () => Promise<void>
filePath: string
Returns: Promise<void>

The file is removed if either:

  • writeFunction() throws an exception or returns a rejected Promise
  • the process exits before writeFunction() completes

Support

If you found a bug or would like a new feature, don't hesitate to submit an issue on GitHub.

For other questions, feel free to chat with us on Gitter.

Everyone is welcome regardless of personal background. We enforce a Code of conduct in order to promote a positive and inclusive environment.

Contributing

This project was made with ❤️. The simplest way to give back is by starring and sharing it online.

If the documentation is unclear or has a typo, please click on the page's Edit button (pencil icon) and suggest a correction.

If you would like to help us fix a bug or add a new feature, please check our guidelines. Pull requests are welcome!

ehmicky
ehmicky

💻 🎨 🤔 📖

Package Sidebar

Install

npm i clean-write

Homepage

git.io/fj7vJ

Weekly Downloads

3

Version

0.0.1

License

Apache-2.0

Unpacked Size

18.3 kB

Total Files

6

Last publish

Collaborators

  • ehmicky