    -- |
    -- Module      :  System.AtomicWrite.Writer.LazyByteString.Binary
    -- Copyright   :  © 2015-2019 Stack Builders Inc.
    -- License     :  MIT
    --
    -- Maintainer  :  Stack Builders <hackage@stackbuilders.com>
    -- Stability   :  experimental
    -- Portability :  portable
    --
    -- Provides functionality to dump the contents of a Lazy ByteString
    -- to a file in binary mode.

    module System.AtomicWrite.Writer.LazyByteString.Binary (atomicWriteFile, atomicWriteFileWithMode) where

    import           System.AtomicWrite.Internal (atomicWriteFileMaybeModeBinary)

    import           Data.ByteString.Lazy        (ByteString, hPutStr)

    import           System.Posix.Types          (FileMode)

    -- | Creates or modifies a file atomically on POSIX-compliant
    -- systems while preserving permissions.
    atomicWriteFile ::
      FilePath      -- ^ The path where the file will be updated or created
      -> ByteString -- ^ The content to write to the file
      -> IO ()
    atomicWriteFile :: FilePath -> ByteString -> IO ()
    atomicWriteFile =
      Maybe FileMode -> FilePath -> ByteString -> IO ()
    atomicWriteFileMaybeMode Maybe FileMode
    forall a. Maybe a
    Nothing

    -- | Creates or modifies a file atomically on
    -- POSIX-compliant systems and updates permissions
    atomicWriteFileWithMode ::
      FileMode      -- ^ The mode to set the file to
      -> FilePath   -- ^ The path where the file will be updated or created
      -> ByteString -- ^ The content to write to the file
      -> IO ()
    atomicWriteFileWithMode :: FileMode -> FilePath -> ByteString -> IO ()
    atomicWriteFileWithMode = Maybe FileMode -> FilePath -> ByteString -> IO ()
    atomicWriteFileMaybeMode (Maybe FileMode -> FilePath -> ByteString -> IO ())
    -> (FileMode -> Maybe FileMode)
    -> FileMode
    -> FilePath
    -> ByteString
    -> IO ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . FileMode -> Maybe FileMode
    forall a. a -> Maybe a
    Just

    -- Helper Function
    atomicWriteFileMaybeMode ::
      Maybe FileMode -- ^ The mode to set the file to
      -> FilePath    -- ^ The path where the file will be updated or created
      -> ByteString  -- ^ The content to write to the file
      -> IO ()
    atomicWriteFileMaybeMode :: Maybe FileMode -> FilePath -> ByteString -> IO ()
    atomicWriteFileMaybeMode Maybe FileMode
    mmode FilePath
    path = Maybe FileMode
    -> FilePath
    -> (Handle -> ByteString -> IO ())
    -> ByteString
    -> IO ()
    forall a.
    Maybe FileMode -> FilePath -> (Handle -> a -> IO ()) -> a -> IO ()
    atomicWriteFileMaybeModeBinary Maybe FileMode
    mmode FilePath
    path Handle -> ByteString -> IO ()
    hPutStr