Debian Codegraph @

src/System/AtomicWrite/Writer/Text/Binary.hs

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