Debian Codegraph @

src/System/AtomicWrite/Writer/ByteString.hs

raw
1 -- |
2 -- Module : System.AtomicWrite.Writer.ByteString
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 ByteString
11 -- to a file in text mode.
12
13 module System.AtomicWrite.Writer.ByteString (atomicWriteFile, atomicWriteFileWithMode) where
14
15 import System.AtomicWrite.Internal (atomicWriteFileMaybeModeText)
16
17 import System.Posix.Types (FileMode)
18
19 import Data.ByteString (ByteString, hPutStr)
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 = atomicWriteFileMaybeMode Nothing
29
30 -- | Creates or modifies a file atomically on POSIX-compliant
31 -- systems and updates permissions.
32 atomicWriteFileWithMode ::
33 FileMode
34 -> FilePath -- ^ The path where the file will be updated or created
35 -> ByteString -- ^ The content to write to the file
36 -> IO ()
37 atomicWriteFileWithMode = atomicWriteFileMaybeMode . Just
38
39 -- | Helper function
40 atomicWriteFileMaybeMode ::
41 Maybe FileMode
42 -> FilePath -- ^ The path where the file will be updated or created
43 -> ByteString -- ^ The content to write to the file
44 -> IO ()
45 atomicWriteFileMaybeMode mmode path = atomicWriteFileMaybeModeText mmode path hPutStr
46