Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/luispedro/safeio
Haskell Library for safe (atomic) IO
https://github.com/luispedro/safeio
haskell io
Last synced: 18 days ago
JSON representation
Haskell Library for safe (atomic) IO
- Host: GitHub
- URL: https://github.com/luispedro/safeio
- Owner: luispedro
- License: other
- Created: 2017-05-29T14:20:48.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-06-26T15:04:14.000Z (over 1 year ago)
- Last Synced: 2024-04-25T23:31:19.074Z (9 months ago)
- Topics: haskell, io
- Language: Haskell
- Size: 22.5 KB
- Stars: 3
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: ChangeLog
- License: COPYING
Awesome Lists containing this project
README
# SafeIO: Haskell library for safe (atomic) IO
[![Hackage](https://img.shields.io/hackage/v/safeio.svg)](https://hackage.haskell.org/package/safeio)
[![Hackage-Deps](https://img.shields.io/hackage-deps/v/safeio.svg)](http://packdeps.haskellers.com/feed?needle=safeio)
[![Stackage (LTS)](http://stackage.org/package/safeio/badge/lts)](http://stackage.org/lts/package/safeio)
[![Travis](https://api.travis-ci.com/luispedro/safeio.png)](https://travis-ci.com/luispedro/safeio)
Atomic IOThis 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](https://www.stackage.org/package/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](mailto:[email protected]) | [Twitter](https://twitter.com/luispedrocoelho)