Debian Codegraph @

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

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