Debian Codegraph @

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

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