-- | Lifted "Data.ByteString.Lazy.Char8".
-- Like the original module, you probably want to import this module qualified
-- to avoid name clashes with the functions provided by "Prelude", e.g.:
--
-- > import Data.ByteString.Lazy (ByteString)
-- > import qualified Data.ByteString.Lazy.Char8 as LBS8
-- > import qualified Effectful.FileSystem.IO.ByteString.Lazy as ELBS
--
module Effectful.FileSystem.IO.ByteString.Lazy
  ( -- * Files
    readFile
  , writeFile
  , appendFile

    -- * I/O with Handles
  , hGetContents
  , hGet
  , hGetNonBlocking
  , hPut
  , hPutNonBlocking
  , hPutStr
  , hPutStrLn
  ) where

import Prelude hiding
  ( appendFile
  , readFile
  , writeFile
  )

import Data.ByteString.Lazy (ByteString)
import Data.ByteString.Lazy.Char8 qualified as LBS8
import System.IO (Handle)

import Effectful
import Effectful.Dispatch.Static
import Effectful.FileSystem

----------------------------------------
-- Files

-- | Lifted 'LBS8.readFile'.
readFile :: FileSystem :> es => FilePath -> Eff es ByteString
readFile :: forall (es :: [Effect]).
(FileSystem :> es) =>
FilePath -> Eff es ByteString
readFile = IO ByteString -> Eff es ByteString
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO ByteString -> Eff es ByteString)
-> (FilePath -> IO ByteString) -> FilePath -> Eff es ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FilePath -> IO ByteString
LBS8.readFile

-- | Lifted 'LBS8.writeFile'.
writeFile :: FileSystem :> es => FilePath -> ByteString -> Eff es ()
writeFile :: forall (es :: [Effect]).
(FileSystem :> es) =>
FilePath -> ByteString -> Eff es ()
writeFile FilePath
fp = IO () -> Eff es ()
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO () -> Eff es ())
-> (ByteString -> IO ()) -> ByteString -> Eff es ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FilePath -> ByteString -> IO ()
LBS8.writeFile FilePath
fp

-- | Lifted 'LBS8.appendFile'.
appendFile :: FileSystem :> es => FilePath -> ByteString -> Eff es ()
appendFile :: forall (es :: [Effect]).
(FileSystem :> es) =>
FilePath -> ByteString -> Eff es ()
appendFile FilePath
fp = IO () -> Eff es ()
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO () -> Eff es ())
-> (ByteString -> IO ()) -> ByteString -> Eff es ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FilePath -> ByteString -> IO ()
LBS8.appendFile FilePath
fp

----------------------------------------
-- I/O with Handles

-- | Lifted 'LBS8.hGetContents'.
hGetContents :: FileSystem :> es => Handle -> Eff es ByteString
hGetContents :: forall (es :: [Effect]).
(FileSystem :> es) =>
Handle -> Eff es ByteString
hGetContents = IO ByteString -> Eff es ByteString
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO ByteString -> Eff es ByteString)
-> (Handle -> IO ByteString) -> Handle -> Eff es ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle -> IO ByteString
LBS8.hGetContents

-- | Lifted 'LBS8.hGet'.
hGet :: FileSystem :> es => Handle -> Int -> Eff es ByteString
hGet :: forall (es :: [Effect]).
(FileSystem :> es) =>
Handle -> Int -> Eff es ByteString
hGet Handle
h = IO ByteString -> Eff es ByteString
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO ByteString -> Eff es ByteString)
-> (Int -> IO ByteString) -> Int -> Eff es ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle -> Int -> IO ByteString
LBS8.hGet Handle
h

-- | Lifted 'LBS8.hGetNonBlocking'.
hGetNonBlocking :: FileSystem :> es => Handle -> Int -> Eff es ByteString
hGetNonBlocking :: forall (es :: [Effect]).
(FileSystem :> es) =>
Handle -> Int -> Eff es ByteString
hGetNonBlocking Handle
h = IO ByteString -> Eff es ByteString
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO ByteString -> Eff es ByteString)
-> (Int -> IO ByteString) -> Int -> Eff es ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle -> Int -> IO ByteString
LBS8.hGetNonBlocking Handle
h

-- | Lifted 'LBS8.hPut'.
hPut :: FileSystem :> es => Handle -> ByteString -> Eff es ()
hPut :: forall (es :: [Effect]).
(FileSystem :> es) =>
Handle -> ByteString -> Eff es ()
hPut Handle
h = IO () -> Eff es ()
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO () -> Eff es ())
-> (ByteString -> IO ()) -> ByteString -> Eff es ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle -> ByteString -> IO ()
LBS8.hPut Handle
h

-- | Lifted 'LBS8.hPutNonBlocking'.
hPutNonBlocking :: FileSystem :> es => Handle -> ByteString -> Eff es ByteString
hPutNonBlocking :: forall (es :: [Effect]).
(FileSystem :> es) =>
Handle -> ByteString -> Eff es ByteString
hPutNonBlocking Handle
h = IO ByteString -> Eff es ByteString
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO ByteString -> Eff es ByteString)
-> (ByteString -> IO ByteString) -> ByteString -> Eff es ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle -> ByteString -> IO ByteString
LBS8.hPutNonBlocking Handle
h

-- | Lifted 'LBS8.hPutStr'.
hPutStr :: FileSystem :> es => Handle -> ByteString -> Eff es ()
hPutStr :: forall (es :: [Effect]).
(FileSystem :> es) =>
Handle -> ByteString -> Eff es ()
hPutStr Handle
h = IO () -> Eff es ()
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO () -> Eff es ())
-> (ByteString -> IO ()) -> ByteString -> Eff es ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle -> ByteString -> IO ()
LBS8.hPutStr Handle
h

-- | Lifted 'LBS8.hPutStrLn'.
hPutStrLn :: FileSystem :> es => Handle -> ByteString -> Eff es ()
hPutStrLn :: forall (es :: [Effect]).
(FileSystem :> es) =>
Handle -> ByteString -> Eff es ()
hPutStrLn Handle
h = IO () -> Eff es ()
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO () -> Eff es ())
-> (ByteString -> IO ()) -> ByteString -> Eff es ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle -> ByteString -> IO ()
LBS8.hPutStrLn Handle
h