safeio: Write output to disk atomically

[ io, library, mit ] [ Propose Tags ]

This package implements utilities to perform atomic output so as to avoid the problem of partial intermediate files.


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 0.0.1.0, 0.0.2.0, 0.0.3.0, 0.0.4.0, 0.0.5.0, 0.0.6.0
Change log ChangeLog
Dependencies base (>4.8 && <5), bytestring, conduit (>=1.0), conduit-combinators, directory, exceptions, filepath, resourcet, unix [details]
License MIT
Author Luis Pedro Coelho
Maintainer Luis Pedro Coelho
Category IO
Home page https://github.com/luispedro/safeio#readme
Bug tracker https://github.com/luispedro/safeio/issues
Source repo head: git clone https://github.com/luispedro/safeio
Uploaded by luispedro at 2023-08-25T17:44:53Z
Distributions LTSHaskell:0.0.6.0, Stackage:0.0.6.0
Reverse Dependencies 2 direct, 0 indirect [details]
Downloads 4010 total (24 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2023-08-25 [all 1 reports]

Readme for safeio-0.0.6.0

[back to package description]

SafeIO: Haskell library for safe (atomic) IO

Hackage Hackage-Deps Stackage (LTS) Travis Atomic IO

This is a simple module, which enables writing in atomic mode. It implements the following 4 step procedure:

  1. Open a temporary file in the same directory as the final output.
  2. Write to this temporary file.
  3. Close and sync the file.
  4. Atomically rename the file to its final destination.

Example

Direct use:

import System.IO.SafeWrite
...
main = do
    withOutputFile "output.txt" $ \hout -> do
        hPutStrLn hout "Hello World"

Through conduit:

import qualified Data.Conduit as C
import           Data.Conduit ((.|))
import           Data.Conduit.SafeWrite

main = C.runConduitRes $
    C.yield "Hello World" .| safeSinkFile "hello.txt"

In any case, only successful termination of the process will result in the output file being written. Early termination by throwing an exception will cause the temporary file to be removed and no output will be produced.

Author

Luis Pedro Coelho | Email | Twitter