{-# OPTIONS_GHC -Wno-redundant-constraints #-}

-- | Provides a static effect for reading a handle.
--
-- @since 0.1
module Effectful.FileSystem.HandleReader.Static
  ( -- * Effect
    HandleReader,
    openBinaryFile,
    withBinaryFile,
    hIsEOF,
    hGetBuffering,
    hIsOpen,
    hIsClosed,
    hIsReadable,
    hIsWritable,
    hIsSeekable,
    hIsTerminalDevice,
    hGetEcho,
    hWaitForInput,
    hReady,
    hGetChar,
    hGetLine,
    hGetContents,
    hGet,
    hGetSome,
    hGetNonBlocking,
    hLockRaw,
    hTryLockRaw,
    hUnlockRaw,

    -- ** Handlers
    runHandleReader,

    -- * File handles
    Handle,
    HandleMode (HandleModeRead),
    CanRead,

    -- * Locking
    -- $locking
    LockedHandle,
    Internal.liftLocked,
    withLockedFile,
    withTryLockedFile,
    hLock,
    hTryLock,
    hUnlock,

    -- ** Raw
    withLockedFileRaw,
    withTryLockedFileRaw,

    -- * UTF-8 Utils

    -- ** GetLine
    hGetLineUtf8,
    hGetLineUtf8Lenient,
    hGetLineUtf8ThrowM,

    -- ** GetContents
    hGetContentsUtf8,
    hGetContentsUtf8Lenient,
    hGetContentsUtf8ThrowM,

    -- ** Get
    hGetUtf8,
    hGetUtf8Lenient,
    hGetUtf8ThrowM,

    -- ** GetSome
    hGetSomeUtf8,
    hGetSomeUtf8Lenient,
    hGetSomeUtf8ThrowM,

    -- ** GetNonBlocking
    hGetNonBlockingUtf8,
    hGetNonBlockingUtf8Lenient,
    hGetNonBlockingUtf8ThrowM,

    -- * Re-exports
    ByteString,
    OsPath,
    Text,
    UnicodeException,
  )
where

import Control.Monad ((>=>))
import Data.ByteString (ByteString)
import Data.ByteString.Char8 qualified as C8
import Data.Text (Text)
import Data.Text.Encoding.Error (UnicodeException)
import Effectful
  ( Dispatch (Static),
    DispatchOf,
    Eff,
    Effect,
    IOE,
    type (:>),
  )
import Effectful.Dispatch.Static
  ( HasCallStack,
    SideEffects (WithSideEffects),
    StaticRep,
    evalStaticRep,
    seqUnliftIO,
    unsafeEff,
    unsafeEff_,
  )
import Effectful.Exception (bracket, bracket_)
import Effectful.FileSystem.Handle.Internal
  ( CanRead,
    Handle (MkHandle),
    HandleMode (HandleModeRead),
    LockedHandle,
  )
import Effectful.FileSystem.Handle.Internal qualified as Internal
import FileSystem.IO (openBinaryFileIO, withBinaryFileIO)
import FileSystem.OsPath (OsPath)
import FileSystem.UTF8 qualified as FS.UTF8
import GHC.IO.Handle.Lock qualified as Lock
import System.IO (BufferMode, IOMode (ReadMode))
import System.IO qualified as IO

-- | Static effect for reading a handle.
--
-- @since 0.1
data HandleReader :: Effect

type instance DispatchOf HandleReader = Static WithSideEffects

data instance StaticRep HandleReader = MkHandleReader

-- | Runs 'HandleReader' in 'IO'.
--
-- @since 0.1
runHandleReader ::
  (HasCallStack, IOE :> es) =>
  Eff (HandleReader : es) a ->
  Eff es a
runHandleReader :: forall (es :: [Effect]) a.
(HasCallStack, IOE :> es) =>
Eff (HandleReader : es) a -> Eff es a
runHandleReader = StaticRep HandleReader -> Eff (HandleReader : es) a -> Eff es a
forall (e :: Effect) (sideEffects :: SideEffects) (es :: [Effect])
       a.
(HasCallStack, DispatchOf e ~ 'Static sideEffects,
 MaybeIOE sideEffects es) =>
StaticRep e -> Eff (e : es) a -> Eff es a
evalStaticRep StaticRep HandleReader
MkHandleReader

-- | Lifted 'IO.openBinaryFile'.
--
-- @since 0.1
openBinaryFile ::
  ( HandleReader :> es,
    HasCallStack
  ) =>
  OsPath ->
  Eff es (Handle HandleModeRead)
openBinaryFile :: forall (es :: [Effect]).
(HandleReader :> es, HasCallStack) =>
OsPath -> Eff es (Handle 'HandleModeRead)
openBinaryFile =
  IO (Handle 'HandleModeRead) -> Eff es (Handle 'HandleModeRead)
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_
    (IO (Handle 'HandleModeRead) -> Eff es (Handle 'HandleModeRead))
-> (OsPath -> IO (Handle 'HandleModeRead))
-> OsPath
-> Eff es (Handle 'HandleModeRead)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Handle -> Handle 'HandleModeRead)
-> IO Handle -> IO (Handle 'HandleModeRead)
forall a b. (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Handle -> Handle 'HandleModeRead
forall (p :: HandleMode). Handle -> Handle p
MkHandle
    (IO Handle -> IO (Handle 'HandleModeRead))
-> (OsPath -> IO Handle) -> OsPath -> IO (Handle 'HandleModeRead)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (\OsPath
p -> OsPath -> IOMode -> IO Handle
openBinaryFileIO OsPath
p IOMode
ReadMode)

-- | Lifted 'IO.withBinaryFile'.
--
-- @since 0.1
withBinaryFile ::
  ( HandleReader :> es,
    HasCallStack
  ) =>
  OsPath ->
  (Handle HandleModeRead -> Eff es a) ->
  Eff es a
withBinaryFile :: forall (es :: [Effect]) a.
(HandleReader :> es, HasCallStack) =>
OsPath -> (Handle 'HandleModeRead -> Eff es a) -> Eff es a
withBinaryFile OsPath
p Handle 'HandleModeRead -> Eff es a
onHandle =
  (Env es -> IO a) -> Eff es a
forall (es :: [Effect]) a. (Env es -> IO a) -> Eff es a
unsafeEff ((Env es -> IO a) -> Eff es a) -> (Env es -> IO a) -> Eff es a
forall a b. (a -> b) -> a -> b
$ \Env es
env -> Env es -> ((forall r. Eff es r -> IO r) -> IO a) -> IO a
forall (es :: [Effect]) a.
HasCallStack =>
Env es -> ((forall r. Eff es r -> IO r) -> IO a) -> IO a
seqUnliftIO Env es
env (((forall r. Eff es r -> IO r) -> IO a) -> IO a)
-> ((forall r. Eff es r -> IO r) -> IO a) -> IO a
forall a b. (a -> b) -> a -> b
$ \forall r. Eff es r -> IO r
unlift ->
    OsPath -> IOMode -> (Handle -> IO a) -> IO a
forall a. OsPath -> IOMode -> (Handle -> IO a) -> IO a
withBinaryFileIO OsPath
p IOMode
ReadMode (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 'HandleModeRead -> Eff es a
onHandle (Handle 'HandleModeRead -> Eff es a)
-> (Handle -> Handle 'HandleModeRead) -> Handle -> Eff es a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle -> Handle 'HandleModeRead
forall (p :: HandleMode). Handle -> Handle p
MkHandle)

-- | Lifted 'IO.hIsEof'.
--
-- @since 0.1
hIsEOF ::
  ( CanRead p,
    HandleReader :> es,
    HasCallStack
  ) =>
  Handle p ->
  Eff es Bool
hIsEOF :: forall (p :: HandleMode) (es :: [Effect]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es Bool
hIsEOF = IO Bool -> Eff es Bool
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO Bool -> Eff es Bool)
-> (Handle p -> IO Bool) -> Handle p -> Eff es Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle -> IO Bool
IO.hIsEOF (Handle -> IO Bool) -> (Handle p -> Handle) -> Handle p -> IO Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle p -> Handle
forall (p :: HandleMode). Handle p -> Handle
Internal.unHandle

-- | Lifted 'IO.hGetBuffering'.
--
-- @since 0.1
hGetBuffering ::
  ( CanRead p,
    HandleReader :> es,
    HasCallStack
  ) =>
  Handle p ->
  Eff es BufferMode
hGetBuffering :: forall (p :: HandleMode) (es :: [Effect]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es BufferMode
hGetBuffering = IO BufferMode -> Eff es BufferMode
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO BufferMode -> Eff es BufferMode)
-> (Handle p -> IO BufferMode) -> Handle p -> Eff es BufferMode
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle -> IO BufferMode
IO.hGetBuffering (Handle -> IO BufferMode)
-> (Handle p -> Handle) -> Handle p -> IO BufferMode
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle p -> Handle
forall (p :: HandleMode). Handle p -> Handle
Internal.unHandle

-- | Lifted 'IO.hIsOpen'.
--
-- @since 0.1
hIsOpen ::
  ( CanRead p,
    HandleReader :> es,
    HasCallStack
  ) =>
  Handle p ->
  Eff es Bool
hIsOpen :: forall (p :: HandleMode) (es :: [Effect]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es Bool
hIsOpen = IO Bool -> Eff es Bool
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO Bool -> Eff es Bool)
-> (Handle p -> IO Bool) -> Handle p -> Eff es Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle -> IO Bool
IO.hIsOpen (Handle -> IO Bool) -> (Handle p -> Handle) -> Handle p -> IO Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle p -> Handle
forall (p :: HandleMode). Handle p -> Handle
Internal.unHandle

-- | Lifted 'IO.hIsClosed'.
--
-- @since 0.1
hIsClosed ::
  ( CanRead p,
    HandleReader :> es,
    HasCallStack
  ) =>
  Handle p ->
  Eff es Bool
hIsClosed :: forall (p :: HandleMode) (es :: [Effect]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es Bool
hIsClosed = IO Bool -> Eff es Bool
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO Bool -> Eff es Bool)
-> (Handle p -> IO Bool) -> Handle p -> Eff es Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle -> IO Bool
IO.hIsClosed (Handle -> IO Bool) -> (Handle p -> Handle) -> Handle p -> IO Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle p -> Handle
forall (p :: HandleMode). Handle p -> Handle
Internal.unHandle

-- | Lifted 'IO.hIsReadable'.
--
-- @since 0.1
hIsReadable ::
  ( CanRead p,
    HandleReader :> es,
    HasCallStack
  ) =>
  Handle p ->
  Eff es Bool
hIsReadable :: forall (p :: HandleMode) (es :: [Effect]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es Bool
hIsReadable = IO Bool -> Eff es Bool
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO Bool -> Eff es Bool)
-> (Handle p -> IO Bool) -> Handle p -> Eff es Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle -> IO Bool
IO.hIsReadable (Handle -> IO Bool) -> (Handle p -> Handle) -> Handle p -> IO Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle p -> Handle
forall (p :: HandleMode). Handle p -> Handle
Internal.unHandle

-- | Lifted 'IO.hIsWritable'.
--
-- @since 0.1
hIsWritable ::
  ( CanRead p,
    HandleReader :> es,
    HasCallStack
  ) =>
  Handle p ->
  Eff es Bool
hIsWritable :: forall (p :: HandleMode) (es :: [Effect]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es Bool
hIsWritable = IO Bool -> Eff es Bool
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO Bool -> Eff es Bool)
-> (Handle p -> IO Bool) -> Handle p -> Eff es Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle -> IO Bool
IO.hIsWritable (Handle -> IO Bool) -> (Handle p -> Handle) -> Handle p -> IO Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle p -> Handle
forall (p :: HandleMode). Handle p -> Handle
Internal.unHandle

-- | Lifted 'IO.hIsSeekable'.
--
-- @since 0.1
hIsSeekable ::
  ( CanRead p,
    HandleReader :> es,
    HasCallStack
  ) =>
  Handle p ->
  Eff es Bool
hIsSeekable :: forall (p :: HandleMode) (es :: [Effect]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es Bool
hIsSeekable = IO Bool -> Eff es Bool
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO Bool -> Eff es Bool)
-> (Handle p -> IO Bool) -> Handle p -> Eff es Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle -> IO Bool
IO.hIsSeekable (Handle -> IO Bool) -> (Handle p -> Handle) -> Handle p -> IO Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle p -> Handle
forall (p :: HandleMode). Handle p -> Handle
Internal.unHandle

-- | Lifted 'IO.hIsTerminalDevice'.
--
-- @since 0.1
hIsTerminalDevice ::
  ( CanRead p,
    HandleReader :> es,
    HasCallStack
  ) =>
  Handle p ->
  Eff es Bool
hIsTerminalDevice :: forall (p :: HandleMode) (es :: [Effect]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es Bool
hIsTerminalDevice = IO Bool -> Eff es Bool
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO Bool -> Eff es Bool)
-> (Handle p -> IO Bool) -> Handle p -> Eff es Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle -> IO Bool
IO.hIsTerminalDevice (Handle -> IO Bool) -> (Handle p -> Handle) -> Handle p -> IO Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle p -> Handle
forall (p :: HandleMode). Handle p -> Handle
Internal.unHandle

-- | Lifted 'IO.hGetEcho'.
--
-- @since 0.1
hGetEcho ::
  ( CanRead p,
    HandleReader :> es,
    HasCallStack
  ) =>
  Handle p ->
  Eff es Bool
hGetEcho :: forall (p :: HandleMode) (es :: [Effect]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es Bool
hGetEcho = IO Bool -> Eff es Bool
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO Bool -> Eff es Bool)
-> (Handle p -> IO Bool) -> Handle p -> Eff es Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle -> IO Bool
IO.hGetEcho (Handle -> IO Bool) -> (Handle p -> Handle) -> Handle p -> IO Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle p -> Handle
forall (p :: HandleMode). Handle p -> Handle
Internal.unHandle

-- | Lifted 'IO.hWaitForInput'.
--
-- @since 0.1
hWaitForInput ::
  ( CanRead p,
    HandleReader :> es,
    HasCallStack
  ) =>
  Handle p ->
  Int ->
  Eff es Bool
hWaitForInput :: forall (p :: HandleMode) (es :: [Effect]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Int -> Eff es Bool
hWaitForInput Handle p
h = IO Bool -> Eff es Bool
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO Bool -> Eff es Bool) -> (Int -> IO Bool) -> Int -> Eff es Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle -> Int -> IO Bool
IO.hWaitForInput (Handle p -> Handle
forall (p :: HandleMode). Handle p -> Handle
Internal.unHandle Handle p
h)

-- | Lifted 'IO.hReady'.
--
-- @since 0.1
hReady ::
  ( CanRead p,
    HandleReader :> es,
    HasCallStack
  ) =>
  Handle p ->
  Eff es Bool
hReady :: forall (p :: HandleMode) (es :: [Effect]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es Bool
hReady = IO Bool -> Eff es Bool
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO Bool -> Eff es Bool)
-> (Handle p -> IO Bool) -> Handle p -> Eff es Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle -> IO Bool
IO.hReady (Handle -> IO Bool) -> (Handle p -> Handle) -> Handle p -> IO Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle p -> Handle
forall (p :: HandleMode). Handle p -> Handle
Internal.unHandle

-- | Lifted 'IO.hGetChar'.
--
-- @since 0.1
hGetChar ::
  ( CanRead p,
    HandleReader :> es,
    HasCallStack
  ) =>
  Handle p ->
  Eff es Char
hGetChar :: forall (p :: HandleMode) (es :: [Effect]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es Char
hGetChar = IO Char -> Eff es Char
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO Char -> Eff es Char)
-> (Handle p -> IO Char) -> Handle p -> Eff es Char
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle -> IO Char
IO.hGetChar (Handle -> IO Char) -> (Handle p -> Handle) -> Handle p -> IO Char
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle p -> Handle
forall (p :: HandleMode). Handle p -> Handle
Internal.unHandle

-- | Lifted 'BS.hGetLine'.
--
-- @since 0.1
hGetLine ::
  ( CanRead p,
    HandleReader :> es,
    HasCallStack
  ) =>
  Handle p ->
  Eff es ByteString
hGetLine :: forall (p :: HandleMode) (es :: [Effect]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es ByteString
hGetLine = IO ByteString -> Eff es ByteString
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO ByteString -> Eff es ByteString)
-> (Handle p -> IO ByteString) -> Handle p -> Eff es ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle -> IO ByteString
C8.hGetLine (Handle -> IO ByteString)
-> (Handle p -> Handle) -> Handle p -> IO ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle p -> Handle
forall (p :: HandleMode). Handle p -> Handle
Internal.unHandle

-- | Lifted 'BS.hGetContents'.
--
-- @since 0.1
hGetContents ::
  ( CanRead p,
    HandleReader :> es,
    HasCallStack
  ) =>
  Handle p ->
  Eff es ByteString
hGetContents :: forall (p :: HandleMode) (es :: [Effect]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> 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 p -> IO ByteString) -> Handle p -> Eff es ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle -> IO ByteString
C8.hGetContents (Handle -> IO ByteString)
-> (Handle p -> Handle) -> Handle p -> IO ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle p -> Handle
forall (p :: HandleMode). Handle p -> Handle
Internal.unHandle

-- | Lifted 'BS.hGet'.
--
-- @since 0.1
hGet ::
  ( CanRead p,
    HandleReader :> es,
    HasCallStack
  ) =>
  Handle p ->
  Int ->
  Eff es ByteString
hGet :: forall (p :: HandleMode) (es :: [Effect]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Int -> Eff es ByteString
hGet Handle p
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
C8.hGet (Handle p -> Handle
forall (p :: HandleMode). Handle p -> Handle
Internal.unHandle Handle p
h)

-- | Lifted 'BS.hGetSome'.
--
-- @since 0.1
hGetSome ::
  ( CanRead p,
    HandleReader :> es,
    HasCallStack
  ) =>
  Handle p ->
  Int ->
  Eff es ByteString
hGetSome :: forall (p :: HandleMode) (es :: [Effect]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Int -> Eff es ByteString
hGetSome Handle p
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
C8.hGetSome (Handle p -> Handle
forall (p :: HandleMode). Handle p -> Handle
Internal.unHandle Handle p
h)

-- | Lifted 'BS.hGetNonBlocking'.
--
-- @since 0.1
hGetNonBlocking ::
  ( CanRead p,
    HandleReader :> es,
    HasCallStack
  ) =>
  Handle p ->
  Int ->
  Eff es ByteString
hGetNonBlocking :: forall (p :: HandleMode) (es :: [Effect]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Int -> Eff es ByteString
hGetNonBlocking Handle p
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
C8.hGetNonBlocking (Handle p -> Handle
forall (p :: HandleMode). Handle p -> Handle
Internal.unHandle Handle p
h)

-- | Attempts to shared lock a file, blocking or throwing an exception
-- upon failure.
--
-- @since 0.1
hLockRaw ::
  ( CanRead p,
    HandleReader :> es,
    HasCallStack
  ) =>
  Handle p ->
  Eff es ()
hLockRaw :: forall (p :: HandleMode) (es :: [Effect]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es ()
hLockRaw Handle p
h = IO () -> Eff es ()
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO () -> Eff es ()) -> IO () -> Eff es ()
forall a b. (a -> b) -> a -> b
$ Handle -> LockMode -> IO ()
Lock.hLock (Handle p -> Handle
forall (p :: HandleMode). Handle p -> Handle
Internal.unHandle Handle p
h) LockMode
Lock.SharedLock

-- | Attempts to shared lock a file.
--
-- @since 0.1
hTryLockRaw ::
  ( CanRead p,
    HandleReader :> es,
    HasCallStack
  ) =>
  Handle p ->
  Eff es Bool
hTryLockRaw :: forall (p :: HandleMode) (es :: [Effect]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es Bool
hTryLockRaw Handle p
h = IO Bool -> Eff es Bool
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO Bool -> Eff es Bool) -> IO Bool -> Eff es Bool
forall a b. (a -> b) -> a -> b
$ Handle -> LockMode -> IO Bool
Lock.hTryLock (Handle p -> Handle
forall (p :: HandleMode). Handle p -> Handle
Internal.unHandle Handle p
h) LockMode
Lock.SharedLock

-- | Unlocks a locked file.
--
-- @since 0.1
hUnlockRaw ::
  ( CanRead p,
    HandleReader :> es,
    HasCallStack
  ) =>
  Handle p ->
  Eff es ()
hUnlockRaw :: forall (p :: HandleMode) (es :: [Effect]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es ()
hUnlockRaw = IO () -> Eff es ()
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO () -> Eff es ())
-> (Handle p -> IO ()) -> Handle p -> Eff es ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle -> IO ()
Lock.hUnlock (Handle -> IO ()) -> (Handle p -> Handle) -> Handle p -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle p -> Handle
forall (p :: HandleMode). Handle p -> Handle
Internal.unHandle

-- $locking
--
-- These functions bring some type-safety to file locking. Consider:
--
-- @
-- main :: (HandleReader :> es) => Eff es ()
-- main = withBinaryFile path False $ \\h -> do
--   hLockRaw handle
--   bs <- readBytes @HandleModeRead h
--   hUnlockRaw handle
--   print bs
--
-- readBytes :: (CanRead p, HandleReader :> es) => Handle p -> Eff es ByteString
-- readBytes handle = hGet handle 1024
-- @
--
-- In this example, we could remove all locking logic from @main@ and
-- everything would still compile. On the other hand:
--
-- @
-- main :: (HandleReader :> es) => Eff es ()
-- main = withBinaryFile path False $ \\h -> withLockedFile h $ \\lh -> do
--   bs <- readBytes @HandleModeRead lh
--   print bs
--
-- readBytes :: (CanRead p, HandleReader :> es) => LockedHandle p -> Eff es ByteString
-- readBytes lockedHandle = liftLocked (\\h -\> hGet h 1024) lockedHandle
-- @
--
-- Removing @withLockedFile@ would cause a compilation error, since @writeBytes@
-- requires a @LockedHandle@. The idea is to write most of the program's
-- logic in terms of @LockedHandle@, using @liftLocked@ to lift @Handle@
-- functions.

-- | Like 'hLockRaw', but returns a 'LockedHandle'.
--
-- @since 0.1
hLock ::
  ( CanRead p,
    HandleReader :> es,
    HasCallStack
  ) =>
  -- | Handle to lock.
  Handle p ->
  Eff es (LockedHandle p)
hLock :: forall (p :: HandleMode) (es :: [Effect]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es (LockedHandle p)
hLock = (Handle p -> Eff es ()) -> Handle p -> Eff es (LockedHandle p)
forall (f :: * -> *) (p :: HandleMode).
Functor f =>
(Handle p -> f ()) -> Handle p -> f (LockedHandle p)
Internal.liftLock Handle p -> Eff es ()
forall (p :: HandleMode) (es :: [Effect]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es ()
hLockRaw

-- | Like 'hTryLockRaw', but returns a 'LockedHandle' if it succeeds.
--
-- @since 0.1
hTryLock ::
  ( CanRead p,
    HandleReader :> es,
    HasCallStack
  ) =>
  -- | Handle to lock.
  Handle p ->
  Eff es (Maybe (LockedHandle p))
hTryLock :: forall (p :: HandleMode) (es :: [Effect]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es (Maybe (LockedHandle p))
hTryLock = (Handle p -> Eff es Bool)
-> Handle p -> Eff es (Maybe (LockedHandle p))
forall (f :: * -> *) (p :: HandleMode).
Functor f =>
(Handle p -> f Bool) -> Handle p -> f (Maybe (LockedHandle p))
Internal.liftTryLock Handle p -> Eff es Bool
forall (p :: HandleMode) (es :: [Effect]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es Bool
hTryLockRaw

-- | Like 'hUnlockRaw', but returns the original handle.
--
-- @since 0.1
hUnlock ::
  ( CanRead p,
    HandleReader :> es,
    HasCallStack
  ) =>
  -- | Handle to unlock.
  LockedHandle p ->
  Eff es (Handle p)
hUnlock :: forall (p :: HandleMode) (es :: [Effect]).
(CanRead p, HandleReader :> es, HasCallStack) =>
LockedHandle p -> Eff es (Handle p)
hUnlock = (Handle p -> Eff es ()) -> LockedHandle p -> Eff es (Handle p)
forall (f :: * -> *) (p :: HandleMode).
Functor f =>
(Handle p -> f ()) -> LockedHandle p -> f (Handle p)
Internal.liftUnlock Handle p -> Eff es ()
forall (p :: HandleMode) (es :: [Effect]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es ()
hUnlockRaw

-- | Runs a computation with a shared locked file.
--
-- @since 0.1
withLockedFile ::
  ( CanRead p,
    HandleReader :> es,
    HasCallStack
  ) =>
  -- | Handle to lock.
  Handle p ->
  -- | Callback with locked handle.
  (LockedHandle p -> Eff es a) ->
  Eff es a
withLockedFile :: forall (p :: HandleMode) (es :: [Effect]) a.
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> (LockedHandle p -> Eff es a) -> Eff es a
withLockedFile = (Handle p -> Eff es ())
-> (Handle p -> Eff es ())
-> Handle p
-> (LockedHandle p -> Eff es a)
-> Eff es a
forall (p :: HandleMode) (es :: [Effect]) a.
HasCallStack =>
(Handle p -> Eff es ())
-> (Handle p -> Eff es ())
-> Handle p
-> (LockedHandle p -> Eff es a)
-> Eff es a
Internal.withLockedFile Handle p -> Eff es ()
forall (p :: HandleMode) (es :: [Effect]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es ()
hLockRaw Handle p -> Eff es ()
forall (p :: HandleMode) (es :: [Effect]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es ()
hUnlockRaw

-- | Like 'withSharedLockedFile', except the lock attempt does not block.
--
-- @since 0.1
withTryLockedFile ::
  forall p a es.
  ( CanRead p,
    HandleReader :> es,
    HasCallStack
  ) =>
  -- | Handle to lock.
  Handle p ->
  -- | Handle callback.
  (LockedHandle p -> Eff es a) ->
  Eff es (Maybe a)
withTryLockedFile :: forall (p :: HandleMode) a (es :: [Effect]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> (LockedHandle p -> Eff es a) -> Eff es (Maybe a)
withTryLockedFile = (Handle p -> Eff es Bool)
-> (Handle p -> Eff es ())
-> Handle p
-> (LockedHandle p -> Eff es a)
-> Eff es (Maybe a)
forall (p :: HandleMode) a (es :: [Effect]).
HasCallStack =>
(Handle p -> Eff es Bool)
-> (Handle p -> Eff es ())
-> Handle p
-> (LockedHandle p -> Eff es a)
-> Eff es (Maybe a)
Internal.withTryLockedFile Handle p -> Eff es Bool
forall (p :: HandleMode) (es :: [Effect]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es Bool
hTryLockRaw Handle p -> Eff es ()
forall (p :: HandleMode) (es :: [Effect]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es ()
hUnlockRaw

-- | 'withLockedFile' without 'LockedHandle'.
--
-- @since 0.1
withLockedFileRaw ::
  ( CanRead p,
    HandleReader :> es,
    HasCallStack
  ) =>
  -- | Handle to lock.
  Handle p ->
  -- | Callback with locked handle.
  Eff es a ->
  Eff es a
withLockedFileRaw :: forall (p :: HandleMode) (es :: [Effect]) a.
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es a -> Eff es a
withLockedFileRaw Handle p
h = Eff es () -> Eff es () -> Eff es a -> Eff es a
forall (es :: [Effect]) a b c.
Eff es a -> Eff es b -> Eff es c -> Eff es c
bracket_ (Handle p -> Eff es ()
forall (p :: HandleMode) (es :: [Effect]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es ()
hLockRaw Handle p
h) (Handle p -> Eff es ()
forall (p :: HandleMode) (es :: [Effect]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es ()
hUnlockRaw Handle p
h)

-- | 'withTryLockedFileRaw' without 'LockedHandle'.
--
-- @since 0.1
withTryLockedFileRaw ::
  forall p a es.
  ( CanRead p,
    HandleReader :> es,
    HasCallStack
  ) =>
  -- | Handle to lock.
  Handle p ->
  -- | Handle callback.
  Eff es a ->
  Eff es (Maybe a)
withTryLockedFileRaw :: forall (p :: HandleMode) a (es :: [Effect]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es a -> Eff es (Maybe a)
withTryLockedFileRaw Handle p
h Eff es a
m =
  Eff es (Maybe ())
-> (Maybe () -> Eff es (Maybe ()))
-> (Maybe () -> Eff es (Maybe a))
-> Eff es (Maybe a)
forall (es :: [Effect]) a b c.
Eff es a -> (a -> Eff es b) -> (a -> Eff es c) -> Eff es c
bracket
    ( do
        locked <- Handle p -> Eff es Bool
forall (p :: HandleMode) (es :: [Effect]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es Bool
hTryLockRaw Handle p
h
        pure $
          if locked
            then Just ()
            else Nothing
    )
    ((() -> Eff es ()) -> Maybe () -> Eff es (Maybe ())
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Maybe a -> f (Maybe b)
traverse (Eff es () -> () -> Eff es ()
forall a b. a -> b -> a
const (Handle p -> Eff es ()
forall (p :: HandleMode) (es :: [Effect]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es ()
hUnlockRaw Handle p
h)))
    ((() -> Eff es a) -> Maybe () -> Eff es (Maybe a)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Maybe a -> f (Maybe b)
traverse (Eff es a -> () -> Eff es a
forall a b. a -> b -> a
const Eff es a
m))

-- | 'hGetLine' and 'FS.UTF8.decodeUtf8'.
--
-- @since 0.1
hGetLineUtf8 ::
  ( CanRead p,
    HandleReader :> es,
    HasCallStack
  ) =>
  Handle p ->
  Eff es (Either UnicodeException Text)
hGetLineUtf8 :: forall (p :: HandleMode) (es :: [Effect]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es (Either UnicodeException Text)
hGetLineUtf8 = (ByteString -> Either UnicodeException Text)
-> Eff es ByteString -> Eff es (Either UnicodeException Text)
forall a b. (a -> b) -> Eff es a -> Eff es b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ByteString -> Either UnicodeException Text
FS.UTF8.decodeUtf8 (Eff es ByteString -> Eff es (Either UnicodeException Text))
-> (Handle p -> Eff es ByteString)
-> Handle p
-> Eff es (Either UnicodeException Text)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle p -> Eff es ByteString
forall (p :: HandleMode) (es :: [Effect]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es ByteString
hGetLine

-- | 'hGetLine' and 'FS.UTF8.decodeUtf8Lenient'.
--
-- @since 0.1
hGetLineUtf8Lenient ::
  ( CanRead p,
    HandleReader :> es,
    HasCallStack
  ) =>
  Handle p ->
  Eff es Text
hGetLineUtf8Lenient :: forall (p :: HandleMode) (es :: [Effect]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es Text
hGetLineUtf8Lenient = (ByteString -> Text) -> Eff es ByteString -> Eff es Text
forall a b. (a -> b) -> Eff es a -> Eff es b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ByteString -> Text
FS.UTF8.decodeUtf8Lenient (Eff es ByteString -> Eff es Text)
-> (Handle p -> Eff es ByteString) -> Handle p -> Eff es Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle p -> Eff es ByteString
forall (p :: HandleMode) (es :: [Effect]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es ByteString
hGetLine

-- | 'hGetLine' and 'FS.UTF8.decodeUtf8ThrowM'.
--
-- @since 0.1
hGetLineUtf8ThrowM ::
  ( CanRead p,
    HandleReader :> es,
    HasCallStack
  ) =>
  Handle p ->
  Eff es Text
hGetLineUtf8ThrowM :: forall (p :: HandleMode) (es :: [Effect]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es Text
hGetLineUtf8ThrowM = Handle p -> Eff es ByteString
forall (p :: HandleMode) (es :: [Effect]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es ByteString
hGetLine (Handle p -> Eff es ByteString)
-> (ByteString -> Eff es Text) -> Handle p -> Eff es Text
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> ByteString -> Eff es Text
forall (m :: * -> *).
(HasCallStack, MonadThrow m) =>
ByteString -> m Text
FS.UTF8.decodeUtf8ThrowM

-- | 'hGetContents' and 'FS.UTF8.decodeUtf8'.
--
-- @since 0.1
hGetContentsUtf8 ::
  ( CanRead p,
    HandleReader :> es,
    HasCallStack
  ) =>
  Handle p ->
  Eff es (Either UnicodeException Text)
hGetContentsUtf8 :: forall (p :: HandleMode) (es :: [Effect]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es (Either UnicodeException Text)
hGetContentsUtf8 = (ByteString -> Either UnicodeException Text)
-> Eff es ByteString -> Eff es (Either UnicodeException Text)
forall a b. (a -> b) -> Eff es a -> Eff es b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ByteString -> Either UnicodeException Text
FS.UTF8.decodeUtf8 (Eff es ByteString -> Eff es (Either UnicodeException Text))
-> (Handle p -> Eff es ByteString)
-> Handle p
-> Eff es (Either UnicodeException Text)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle p -> Eff es ByteString
forall (p :: HandleMode) (es :: [Effect]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es ByteString
hGetContents

-- | 'hGetContents' and 'FS.UTF8.decodeUtf8Lenient'.
--
-- @since 0.1
hGetContentsUtf8Lenient ::
  ( CanRead p,
    HandleReader :> es,
    HasCallStack
  ) =>
  Handle p ->
  Eff es Text
hGetContentsUtf8Lenient :: forall (p :: HandleMode) (es :: [Effect]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es Text
hGetContentsUtf8Lenient = (ByteString -> Text) -> Eff es ByteString -> Eff es Text
forall a b. (a -> b) -> Eff es a -> Eff es b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ByteString -> Text
FS.UTF8.decodeUtf8Lenient (Eff es ByteString -> Eff es Text)
-> (Handle p -> Eff es ByteString) -> Handle p -> Eff es Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle p -> Eff es ByteString
forall (p :: HandleMode) (es :: [Effect]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es ByteString
hGetContents

-- | 'hGetContents' and 'FS.UTF8.decodeUtf8ThrowM'.
--
-- @since 0.1
hGetContentsUtf8ThrowM ::
  ( CanRead p,
    HandleReader :> es,
    HasCallStack
  ) =>
  Handle p ->
  Eff es Text
hGetContentsUtf8ThrowM :: forall (p :: HandleMode) (es :: [Effect]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es Text
hGetContentsUtf8ThrowM = Handle p -> Eff es ByteString
forall (p :: HandleMode) (es :: [Effect]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Eff es ByteString
hGetContents (Handle p -> Eff es ByteString)
-> (ByteString -> Eff es Text) -> Handle p -> Eff es Text
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> ByteString -> Eff es Text
forall (m :: * -> *).
(HasCallStack, MonadThrow m) =>
ByteString -> m Text
FS.UTF8.decodeUtf8ThrowM

-- | 'hGet' and 'FS.UTF8.decodeUtf8'.
--
-- @since 0.1
hGetUtf8 ::
  ( CanRead p,
    HandleReader :> es,
    HasCallStack
  ) =>
  Handle p ->
  Int ->
  Eff es (Either UnicodeException Text)
hGetUtf8 :: forall (p :: HandleMode) (es :: [Effect]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Int -> Eff es (Either UnicodeException Text)
hGetUtf8 Handle p
h = (ByteString -> Either UnicodeException Text)
-> Eff es ByteString -> Eff es (Either UnicodeException Text)
forall a b. (a -> b) -> Eff es a -> Eff es b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ByteString -> Either UnicodeException Text
FS.UTF8.decodeUtf8 (Eff es ByteString -> Eff es (Either UnicodeException Text))
-> (Int -> Eff es ByteString)
-> Int
-> Eff es (Either UnicodeException Text)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle p -> Int -> Eff es ByteString
forall (p :: HandleMode) (es :: [Effect]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Int -> Eff es ByteString
hGet Handle p
h

-- | 'hGet' and 'FS.UTF8.decodeUtf8Lenient'.
--
-- @since 0.1
hGetUtf8Lenient ::
  ( CanRead p,
    HandleReader :> es,
    HasCallStack
  ) =>
  Handle p ->
  Int ->
  Eff es Text
hGetUtf8Lenient :: forall (p :: HandleMode) (es :: [Effect]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Int -> Eff es Text
hGetUtf8Lenient Handle p
h = (ByteString -> Text) -> Eff es ByteString -> Eff es Text
forall a b. (a -> b) -> Eff es a -> Eff es b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ByteString -> Text
FS.UTF8.decodeUtf8Lenient (Eff es ByteString -> Eff es Text)
-> (Int -> Eff es ByteString) -> Int -> Eff es Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle p -> Int -> Eff es ByteString
forall (p :: HandleMode) (es :: [Effect]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Int -> Eff es ByteString
hGet Handle p
h

-- | 'hGet' and 'FS.UTF8.decodeUtf8ThrowM'.
--
-- @since 0.1
hGetUtf8ThrowM ::
  ( CanRead p,
    HandleReader :> es,
    HasCallStack
  ) =>
  Handle p ->
  Int ->
  Eff es Text
hGetUtf8ThrowM :: forall (p :: HandleMode) (es :: [Effect]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Int -> Eff es Text
hGetUtf8ThrowM Handle p
h = Handle p -> Int -> Eff es ByteString
forall (p :: HandleMode) (es :: [Effect]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Int -> Eff es ByteString
hGet Handle p
h (Int -> Eff es ByteString)
-> (ByteString -> Eff es Text) -> Int -> Eff es Text
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> ByteString -> Eff es Text
forall (m :: * -> *).
(HasCallStack, MonadThrow m) =>
ByteString -> m Text
FS.UTF8.decodeUtf8ThrowM

-- | 'hGetSome' and 'FS.UTF8.decodeUtf8'.
--
-- @since 0.1
hGetSomeUtf8 ::
  ( CanRead p,
    HandleReader :> es,
    HasCallStack
  ) =>
  Handle p ->
  Int ->
  Eff es (Either UnicodeException Text)
hGetSomeUtf8 :: forall (p :: HandleMode) (es :: [Effect]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Int -> Eff es (Either UnicodeException Text)
hGetSomeUtf8 Handle p
h = (ByteString -> Either UnicodeException Text)
-> Eff es ByteString -> Eff es (Either UnicodeException Text)
forall a b. (a -> b) -> Eff es a -> Eff es b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ByteString -> Either UnicodeException Text
FS.UTF8.decodeUtf8 (Eff es ByteString -> Eff es (Either UnicodeException Text))
-> (Int -> Eff es ByteString)
-> Int
-> Eff es (Either UnicodeException Text)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle p -> Int -> Eff es ByteString
forall (p :: HandleMode) (es :: [Effect]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Int -> Eff es ByteString
hGetSome Handle p
h

-- | 'hGetSome' and 'FS.UTF8.decodeUtf8Lenient'.
--
-- @since 0.1
hGetSomeUtf8Lenient ::
  ( CanRead p,
    HandleReader :> es,
    HasCallStack
  ) =>
  Handle p ->
  Int ->
  Eff es Text
hGetSomeUtf8Lenient :: forall (p :: HandleMode) (es :: [Effect]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Int -> Eff es Text
hGetSomeUtf8Lenient Handle p
h = (ByteString -> Text) -> Eff es ByteString -> Eff es Text
forall a b. (a -> b) -> Eff es a -> Eff es b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ByteString -> Text
FS.UTF8.decodeUtf8Lenient (Eff es ByteString -> Eff es Text)
-> (Int -> Eff es ByteString) -> Int -> Eff es Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle p -> Int -> Eff es ByteString
forall (p :: HandleMode) (es :: [Effect]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Int -> Eff es ByteString
hGetSome Handle p
h

-- | 'hGetSome' and 'FS.UTF8.decodeUtf8ThrowM'.
--
-- @since 0.1
hGetSomeUtf8ThrowM ::
  ( CanRead p,
    HandleReader :> es,
    HasCallStack
  ) =>
  Handle p ->
  Int ->
  Eff es Text
hGetSomeUtf8ThrowM :: forall (p :: HandleMode) (es :: [Effect]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Int -> Eff es Text
hGetSomeUtf8ThrowM Handle p
h = Handle p -> Int -> Eff es ByteString
forall (p :: HandleMode) (es :: [Effect]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Int -> Eff es ByteString
hGetSome Handle p
h (Int -> Eff es ByteString)
-> (ByteString -> Eff es Text) -> Int -> Eff es Text
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> ByteString -> Eff es Text
forall (m :: * -> *).
(HasCallStack, MonadThrow m) =>
ByteString -> m Text
FS.UTF8.decodeUtf8ThrowM

-- | 'hGetNonBlocking' and 'FS.UTF8.decodeUtf8'.
--
-- @since 0.1
hGetNonBlockingUtf8 ::
  ( CanRead p,
    HandleReader :> es,
    HasCallStack
  ) =>
  Handle p ->
  Int ->
  Eff es (Either UnicodeException Text)
hGetNonBlockingUtf8 :: forall (p :: HandleMode) (es :: [Effect]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Int -> Eff es (Either UnicodeException Text)
hGetNonBlockingUtf8 Handle p
h = (ByteString -> Either UnicodeException Text)
-> Eff es ByteString -> Eff es (Either UnicodeException Text)
forall a b. (a -> b) -> Eff es a -> Eff es b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ByteString -> Either UnicodeException Text
FS.UTF8.decodeUtf8 (Eff es ByteString -> Eff es (Either UnicodeException Text))
-> (Int -> Eff es ByteString)
-> Int
-> Eff es (Either UnicodeException Text)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle p -> Int -> Eff es ByteString
forall (p :: HandleMode) (es :: [Effect]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Int -> Eff es ByteString
hGetNonBlocking Handle p
h

-- | 'hGetNonBlocking' and 'FS.UTF8.decodeUtf8Lenient'.
--
-- @since 0.1
hGetNonBlockingUtf8Lenient ::
  ( CanRead p,
    HandleReader :> es,
    HasCallStack
  ) =>
  Handle p ->
  Int ->
  Eff es Text
hGetNonBlockingUtf8Lenient :: forall (p :: HandleMode) (es :: [Effect]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Int -> Eff es Text
hGetNonBlockingUtf8Lenient Handle p
h = (ByteString -> Text) -> Eff es ByteString -> Eff es Text
forall a b. (a -> b) -> Eff es a -> Eff es b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ByteString -> Text
FS.UTF8.decodeUtf8Lenient (Eff es ByteString -> Eff es Text)
-> (Int -> Eff es ByteString) -> Int -> Eff es Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle p -> Int -> Eff es ByteString
forall (p :: HandleMode) (es :: [Effect]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Int -> Eff es ByteString
hGetNonBlocking Handle p
h

-- | 'hGetNonBlocking' and 'FS.UTF8.decodeUtf8ThrowM'.
--
-- @since 0.1
hGetNonBlockingUtf8ThrowM ::
  ( CanRead p,
    HandleReader :> es,
    HasCallStack
  ) =>
  Handle p ->
  Int ->
  Eff es Text
hGetNonBlockingUtf8ThrowM :: forall (p :: HandleMode) (es :: [Effect]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Int -> Eff es Text
hGetNonBlockingUtf8ThrowM Handle p
h = Handle p -> Int -> Eff es ByteString
forall (p :: HandleMode) (es :: [Effect]).
(CanRead p, HandleReader :> es, HasCallStack) =>
Handle p -> Int -> Eff es ByteString
hGetNonBlocking Handle p
h (Int -> Eff es ByteString)
-> (ByteString -> Eff es Text) -> Int -> Eff es Text
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> ByteString -> Eff es Text
forall (m :: * -> *).
(HasCallStack, MonadThrow m) =>
ByteString -> m Text
FS.UTF8.decodeUtf8ThrowM