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 = const writeFile = const promisify = const writeFileAsync = const filePath = './path/to/file.js'const writeFunction = { await } // If an exception happens or if the program exits, the file will be removedawait
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 rejectedPromise
- 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 💻 🎨 🤔 📖 |