| 1 |
-- | |
| 2 |
-- Module : System.AtomicWrite.Writer.LazyByteString.Binary |
| 3 |
-- Copyright : © 2015-2019 Stack Builders Inc. |
| 4 |
-- License : MIT |
| 5 |
-- |
| 6 |
-- Maintainer : Stack Builders <[email protected]> |
| 7 |
-- Stability : experimental |
| 8 |
-- Portability : portable |
| 9 |
-- |
| 10 |
-- Provides functionality to dump the contents of a Lazy ByteString |
| 11 |
-- to a file in binary mode. |
| 12 |
|
| 13 |
module System.AtomicWrite.Writer.LazyByteString.Binary (atomicWriteFile, atomicWriteFileWithMode) where |
| 14 |
|
| 15 |
import System.AtomicWrite.Internal (atomicWriteFileMaybeModeBinary) |
| 16 |
|
| 17 |
import Data.ByteString.Lazy (ByteString, hPutStr) |
| 18 |
|
| 19 |
import System.Posix.Types (FileMode) |
| 20 |
|
| 21 |
|
| 22 |
-- | Creates or modifies a file atomically on POSIX-compliant |
| 23 |
-- systems while preserving permissions. |
| 24 |
atomicWriteFile :: |
| 25 |
FilePath -- ^ The path where the file will be updated or created |
| 26 |
-> ByteString -- ^ The content to write to the file |
| 27 |
-> IO () |
| 28 |
atomicWriteFile = |
| 29 |
atomicWriteFileMaybeMode Nothing |
| 30 |
|
| 31 |
-- | Creates or modifies a file atomically on |
| 32 |
-- POSIX-compliant systems and updates permissions |
| 33 |
atomicWriteFileWithMode :: |
| 34 |
FileMode -- ^ The mode to set the file to |
| 35 |
-> FilePath -- ^ The path where the file will be updated or created |
| 36 |
-> ByteString -- ^ The content to write to the file |
| 37 |
-> IO () |
| 38 |
atomicWriteFileWithMode = atomicWriteFileMaybeMode . Just |
| 39 |
|
| 40 |
-- Helper Function |
| 41 |
atomicWriteFileMaybeMode :: |
| 42 |
Maybe FileMode -- ^ The mode to set the file to |
| 43 |
-> FilePath -- ^ The path where the file will be updated or created |
| 44 |
-> ByteString -- ^ The content to write to the file |
| 45 |
-> IO () |
| 46 |
atomicWriteFileMaybeMode mmode path = atomicWriteFileMaybeModeBinary mmode path hPutStr |