safeio- Write output to disk atomically

Safe HaskellSafe




withOutputFile Source #


:: (MonadMask m, MonadIO m) 
=> FilePath

Final desired file path

-> (Handle -> m a)

action to execute

-> m a 

Variation of withFile for output files.

Output is written to a temporary file. Once the action has completed, this file is then sync'ed to disk (see |syncFile|) and renamed to its final destination. In Posix, this is an atomic operation. If an exception is raised, then the temporary output file will be deleted and not saved to disk. Thus, the result file will either contain the complete result or will be empty.

syncFile Source #


:: FilePath

File to sync

-> IO () 

Sync a file to disk

On Windows, this is a fake function.