Debian Codegraph @

src/System/AtomicWrite/Writer/LazyByteString.hs

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