Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

clean-write

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

clean-write

Cleanup corrupted files on write errors

  • 0.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

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

💻 🎨 🤔 📖

Keywords

FAQs

Package last updated on 08 Aug 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc