Debian Codegraph @

src/System/AtomicWrite/Writer/LazyText.hs

raw
1 -- |
2 -- Module : System.AtomicWrite.Writer.LazyText
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.
12
13 module System.AtomicWrite.Writer.LazyText (atomicWriteFile, atomicWriteFileWithMode) where
14
15 import System.AtomicWrite.Internal (atomicWriteFileMaybeModeText)
16
17 import Data.Text.Lazy (Text)
18
19 import Data.Text.Lazy.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 = atomicWriteFileMaybeModeText mmode path hPutStr