module Effectful.FileSystem.File.OsPath
(
FileSystem
, runFileSystem
, IOMode (..)
, Handle
, openBinaryFile
, withFile
, withBinaryFile
, withFile'
, withBinaryFile'
, readFile
, readFile'
, writeFile
, writeFile'
, appendFile
, appendFile'
, openFile
, openExistingFile
, openTempFile
, openBinaryTempFile
, openTempFileWithDefaultPermissions
, openBinaryTempFileWithDefaultPermissions
) where
import Data.ByteString (ByteString)
import Data.ByteString.Lazy qualified as BSL
import Prelude hiding (appendFile, readFile, writeFile)
import System.File.OsPath qualified as F
import System.IO (Handle, IOMode (..))
import System.OsPath (OsPath, OsString)
import Effectful
import Effectful.Dispatch.Static
import Effectful.FileSystem.Effect
openBinaryFile :: FileSystem :> es => OsPath -> IOMode -> Eff es Handle
openBinaryFile :: forall (es :: [Effect]).
(FileSystem :> es) =>
OsPath -> IOMode -> Eff es Handle
openBinaryFile OsPath
path = IO Handle -> Eff es Handle
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO Handle -> Eff es Handle)
-> (IOMode -> IO Handle) -> IOMode -> Eff es Handle
forall b c a. (b -> c) -> (a -> b) -> a -> c
. OsPath -> IOMode -> IO Handle
F.openBinaryFile OsPath
path
withFile
:: FileSystem :> es
=> OsPath
-> IOMode
-> (Handle -> Eff es a)
-> Eff es a
withFile :: forall (es :: [Effect]) a.
(FileSystem :> es) =>
OsPath -> IOMode -> (Handle -> Eff es a) -> Eff es a
withFile OsPath
path IOMode
mode Handle -> Eff es a
inner = ((forall r. Eff es r -> IO r) -> IO a) -> Eff es a
forall (es :: [Effect]) a.
HasCallStack =>
((forall r. Eff es r -> IO r) -> IO a) -> Eff es a
unsafeSeqUnliftIO (((forall r. Eff es r -> IO r) -> IO a) -> Eff es a)
-> ((forall r. Eff es r -> IO r) -> IO a) -> Eff es a
forall a b. (a -> b) -> a -> b
$ \forall r. Eff es r -> IO r
unlift -> do
OsPath -> IOMode -> (Handle -> IO a) -> IO a
forall r. OsPath -> IOMode -> (Handle -> IO r) -> IO r
F.withFile OsPath
path IOMode
mode ((Handle -> IO a) -> IO a) -> (Handle -> IO a) -> IO a
forall a b. (a -> b) -> a -> b
$ Eff es a -> IO a
forall r. Eff es r -> IO r
unlift (Eff es a -> IO a) -> (Handle -> Eff es a) -> Handle -> IO a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle -> Eff es a
inner
withBinaryFile
:: FileSystem :> es
=> OsPath
-> IOMode
-> (Handle -> Eff es a)
-> Eff es a
withBinaryFile :: forall (es :: [Effect]) a.
(FileSystem :> es) =>
OsPath -> IOMode -> (Handle -> Eff es a) -> Eff es a
withBinaryFile OsPath
path IOMode
mode Handle -> Eff es a
inner = ((forall r. Eff es r -> IO r) -> IO a) -> Eff es a
forall (es :: [Effect]) a.
HasCallStack =>
((forall r. Eff es r -> IO r) -> IO a) -> Eff es a
unsafeSeqUnliftIO (((forall r. Eff es r -> IO r) -> IO a) -> Eff es a)
-> ((forall r. Eff es r -> IO r) -> IO a) -> Eff es a
forall a b. (a -> b) -> a -> b
$ \forall r. Eff es r -> IO r
unlift -> do
OsPath -> IOMode -> (Handle -> IO a) -> IO a
forall r. OsPath -> IOMode -> (Handle -> IO r) -> IO r
F.withBinaryFile OsPath
path IOMode
mode ((Handle -> IO a) -> IO a) -> (Handle -> IO a) -> IO a
forall a b. (a -> b) -> a -> b
$ Eff es a -> IO a
forall r. Eff es r -> IO r
unlift (Eff es a -> IO a) -> (Handle -> Eff es a) -> Handle -> IO a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle -> Eff es a
inner
withFile'
:: FileSystem :> es
=> OsPath
-> IOMode
-> (Handle -> Eff es a)
-> Eff es a
withFile' :: forall (es :: [Effect]) a.
(FileSystem :> es) =>
OsPath -> IOMode -> (Handle -> Eff es a) -> Eff es a
withFile' OsPath
path IOMode
mode Handle -> Eff es a
inner = ((forall r. Eff es r -> IO r) -> IO a) -> Eff es a
forall (es :: [Effect]) a.
HasCallStack =>
((forall r. Eff es r -> IO r) -> IO a) -> Eff es a
unsafeSeqUnliftIO (((forall r. Eff es r -> IO r) -> IO a) -> Eff es a)
-> ((forall r. Eff es r -> IO r) -> IO a) -> Eff es a
forall a b. (a -> b) -> a -> b
$ \forall r. Eff es r -> IO r
unlift -> do
OsPath -> IOMode -> (Handle -> IO a) -> IO a
forall r. OsPath -> IOMode -> (Handle -> IO r) -> IO r
F.withFile' OsPath
path IOMode
mode ((Handle -> IO a) -> IO a) -> (Handle -> IO a) -> IO a
forall a b. (a -> b) -> a -> b
$ Eff es a -> IO a
forall r. Eff es r -> IO r
unlift (Eff es a -> IO a) -> (Handle -> Eff es a) -> Handle -> IO a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle -> Eff es a
inner
withBinaryFile'
:: FileSystem :> es
=> OsPath
-> IOMode
-> (Handle -> Eff es a)
-> Eff es a
withBinaryFile' :: forall (es :: [Effect]) a.
(FileSystem :> es) =>
OsPath -> IOMode -> (Handle -> Eff es a) -> Eff es a
withBinaryFile' OsPath
path IOMode
mode Handle -> Eff es a
inner = ((forall r. Eff es r -> IO r) -> IO a) -> Eff es a
forall (es :: [Effect]) a.
HasCallStack =>
((forall r. Eff es r -> IO r) -> IO a) -> Eff es a
unsafeSeqUnliftIO (((forall r. Eff es r -> IO r) -> IO a) -> Eff es a)
-> ((forall r. Eff es r -> IO r) -> IO a) -> Eff es a
forall a b. (a -> b) -> a -> b
$ \forall r. Eff es r -> IO r
unlift -> do
OsPath -> IOMode -> (Handle -> IO a) -> IO a
forall r. OsPath -> IOMode -> (Handle -> IO r) -> IO r
F.withBinaryFile' OsPath
path IOMode
mode ((Handle -> IO a) -> IO a) -> (Handle -> IO a) -> IO a
forall a b. (a -> b) -> a -> b
$ Eff es a -> IO a
forall r. Eff es r -> IO r
unlift (Eff es a -> IO a) -> (Handle -> Eff es a) -> Handle -> IO a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle -> Eff es a
inner
readFile :: FileSystem :> es => OsPath -> Eff es BSL.ByteString
readFile :: forall (es :: [Effect]).
(FileSystem :> es) =>
OsPath -> Eff es ByteString
readFile = IO ByteString -> Eff es ByteString
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO ByteString -> Eff es ByteString)
-> (OsPath -> IO ByteString) -> OsPath -> Eff es ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. OsPath -> IO ByteString
F.readFile
readFile' :: FileSystem :> es => OsPath -> Eff es ByteString
readFile' :: forall (es :: [Effect]).
(FileSystem :> es) =>
OsPath -> Eff es ByteString
readFile' = IO ByteString -> Eff es ByteString
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO ByteString -> Eff es ByteString)
-> (OsPath -> IO ByteString) -> OsPath -> Eff es ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. OsPath -> IO ByteString
F.readFile'
writeFile :: FileSystem :> es => OsPath -> BSL.ByteString -> Eff es ()
writeFile :: forall (es :: [Effect]).
(FileSystem :> es) =>
OsPath -> ByteString -> Eff es ()
writeFile OsPath
path = 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
. OsPath -> ByteString -> IO ()
F.writeFile OsPath
path
writeFile' :: FileSystem :> es => OsPath -> ByteString -> Eff es ()
writeFile' :: forall (es :: [Effect]).
(FileSystem :> es) =>
OsPath -> ByteString -> Eff es ()
writeFile' OsPath
path = 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
. OsPath -> ByteString -> IO ()
F.writeFile' OsPath
path
appendFile :: FileSystem :> es => OsPath -> BSL.ByteString -> Eff es ()
appendFile :: forall (es :: [Effect]).
(FileSystem :> es) =>
OsPath -> ByteString -> Eff es ()
appendFile OsPath
path = 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
. OsPath -> ByteString -> IO ()
F.appendFile OsPath
path
appendFile' :: FileSystem :> es => OsPath -> ByteString -> Eff es ()
appendFile' :: forall (es :: [Effect]).
(FileSystem :> es) =>
OsPath -> ByteString -> Eff es ()
appendFile' OsPath
path = 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
. OsPath -> ByteString -> IO ()
F.appendFile' OsPath
path
openFile :: FileSystem :> es => OsPath -> IOMode -> Eff es Handle
openFile :: forall (es :: [Effect]).
(FileSystem :> es) =>
OsPath -> IOMode -> Eff es Handle
openFile OsPath
path = IO Handle -> Eff es Handle
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO Handle -> Eff es Handle)
-> (IOMode -> IO Handle) -> IOMode -> Eff es Handle
forall b c a. (b -> c) -> (a -> b) -> a -> c
. OsPath -> IOMode -> IO Handle
F.openFile OsPath
path
openExistingFile :: FileSystem :> es => OsPath -> IOMode -> Eff es Handle
openExistingFile :: forall (es :: [Effect]).
(FileSystem :> es) =>
OsPath -> IOMode -> Eff es Handle
openExistingFile OsPath
path = IO Handle -> Eff es Handle
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO Handle -> Eff es Handle)
-> (IOMode -> IO Handle) -> IOMode -> Eff es Handle
forall b c a. (b -> c) -> (a -> b) -> a -> c
. OsPath -> IOMode -> IO Handle
F.openExistingFile OsPath
path
openTempFile
:: FileSystem :> es
=> OsPath
-> OsString
-> Eff es (OsPath, Handle)
openTempFile :: forall (es :: [Effect]).
(FileSystem :> es) =>
OsPath -> OsPath -> Eff es (OsPath, Handle)
openTempFile OsPath
dir = IO (OsPath, Handle) -> Eff es (OsPath, Handle)
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO (OsPath, Handle) -> Eff es (OsPath, Handle))
-> (OsPath -> IO (OsPath, Handle))
-> OsPath
-> Eff es (OsPath, Handle)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. OsPath -> OsPath -> IO (OsPath, Handle)
F.openTempFile OsPath
dir
openBinaryTempFile
:: FileSystem :> es
=> OsPath
-> OsString
-> Eff es (OsPath, Handle)
openBinaryTempFile :: forall (es :: [Effect]).
(FileSystem :> es) =>
OsPath -> OsPath -> Eff es (OsPath, Handle)
openBinaryTempFile OsPath
dir = IO (OsPath, Handle) -> Eff es (OsPath, Handle)
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO (OsPath, Handle) -> Eff es (OsPath, Handle))
-> (OsPath -> IO (OsPath, Handle))
-> OsPath
-> Eff es (OsPath, Handle)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. OsPath -> OsPath -> IO (OsPath, Handle)
F.openBinaryTempFile OsPath
dir
openTempFileWithDefaultPermissions
:: FileSystem :> es
=> OsPath
-> OsString
-> Eff es (OsPath, Handle)
openTempFileWithDefaultPermissions :: forall (es :: [Effect]).
(FileSystem :> es) =>
OsPath -> OsPath -> Eff es (OsPath, Handle)
openTempFileWithDefaultPermissions OsPath
dir =
IO (OsPath, Handle) -> Eff es (OsPath, Handle)
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO (OsPath, Handle) -> Eff es (OsPath, Handle))
-> (OsPath -> IO (OsPath, Handle))
-> OsPath
-> Eff es (OsPath, Handle)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. OsPath -> OsPath -> IO (OsPath, Handle)
F.openTempFileWithDefaultPermissions OsPath
dir
openBinaryTempFileWithDefaultPermissions
:: FileSystem :> es
=> OsPath
-> OsString
-> Eff es (OsPath, Handle)
openBinaryTempFileWithDefaultPermissions :: forall (es :: [Effect]).
(FileSystem :> es) =>
OsPath -> OsPath -> Eff es (OsPath, Handle)
openBinaryTempFileWithDefaultPermissions OsPath
dir =
IO (OsPath, Handle) -> Eff es (OsPath, Handle)
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO (OsPath, Handle) -> Eff es (OsPath, Handle))
-> (OsPath -> IO (OsPath, Handle))
-> OsPath
-> Eff es (OsPath, Handle)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. OsPath -> OsPath -> IO (OsPath, Handle)
F.openBinaryTempFileWithDefaultPermissions OsPath
dir