{-# LANGUAGE NoImplicitPrelude #-}

-- | Strict @ByteString@. Import as:
--
-- > import qualified RIO.ByteString as B
--
-- This module does not export any partial functions.  For those, see
-- "RIO.ByteString.Partial"
module RIO.ByteString
  ( module Data.ByteString
  , module RIO.ByteString
  ) where

import Data.ByteString hiding (head, last, tail, init, foldl1, foldl1', foldr1, foldr1', maximum, minimum, findSubstring, findSubstrings, packCString, packCStringLen, useAsCString, useAsCStringLen, getLine, getContents, putStr, putStrLn, interact, readFile, writeFile, appendFile, hGetLine, hGetContents, hGet, hGetSome, hGetNonBlocking, hPut, hPutNonBlocking, hPutStr, hPutStrLn, breakByte)
import qualified Data.ByteString as B
import RIO
import Foreign.C.String (CString, CStringLen)

-- | Lifted 'B.packCString'
packCString :: MonadIO m => CString -> m ByteString
packCString :: CString -> m ByteString
packCString = IO ByteString -> m ByteString
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO ByteString -> m ByteString)
-> (CString -> IO ByteString) -> CString -> m ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CString -> IO ByteString
B.packCString

-- | Lifted 'B.packCStringLen'
packCStringLen :: MonadIO m => CStringLen -> m ByteString
packCStringLen :: CStringLen -> m ByteString
packCStringLen = IO ByteString -> m ByteString
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO ByteString -> m ByteString)
-> (CStringLen -> IO ByteString) -> CStringLen -> m ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CStringLen -> IO ByteString
B.packCStringLen

-- | Unlifted 'B.useAsCString'
useAsCString :: MonadUnliftIO m => ByteString -> (CString -> m a) -> m a
useAsCString :: ByteString -> (CString -> m a) -> m a
useAsCString ByteString
bs CString -> m a
inner = ((forall a. m a -> IO a) -> IO a) -> m a
forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO (((forall a. m a -> IO a) -> IO a) -> m a)
-> ((forall a. m a -> IO a) -> IO a) -> m a
forall a b. (a -> b) -> a -> b
$ \forall a. m a -> IO a
run -> ByteString -> (CString -> IO a) -> IO a
forall a. ByteString -> (CString -> IO a) -> IO a
B.useAsCString ByteString
bs ((CString -> IO a) -> IO a) -> (CString -> IO a) -> IO a
forall a b. (a -> b) -> a -> b
$ m a -> IO a
forall a. m a -> IO a
run (m a -> IO a) -> (CString -> m a) -> CString -> IO a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CString -> m a
inner

-- | Unlifted 'B.useAsCStringLen'
useAsCStringLen :: MonadUnliftIO m => ByteString -> (CStringLen -> m a) -> m a
useAsCStringLen :: ByteString -> (CStringLen -> m a) -> m a
useAsCStringLen ByteString
bs CStringLen -> m a
inner = ((forall a. m a -> IO a) -> IO a) -> m a
forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO (((forall a. m a -> IO a) -> IO a) -> m a)
-> ((forall a. m a -> IO a) -> IO a) -> m a
forall a b. (a -> b) -> a -> b
$ \forall a. m a -> IO a
run -> ByteString -> (CStringLen -> IO a) -> IO a
forall a. ByteString -> (CStringLen -> IO a) -> IO a
B.useAsCStringLen ByteString
bs ((CStringLen -> IO a) -> IO a) -> (CStringLen -> IO a) -> IO a
forall a b. (a -> b) -> a -> b
$ m a -> IO a
forall a. m a -> IO a
run (m a -> IO a) -> (CStringLen -> m a) -> CStringLen -> IO a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CStringLen -> m a
inner

-- | Lifted 'B.getLine'
getLine :: MonadIO m => m ByteString
getLine :: m ByteString
getLine = IO ByteString -> m ByteString
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO ByteString
B.getLine

-- | Lifted 'B.getContents'
getContents :: MonadIO m => m ByteString
getContents :: m ByteString
getContents = IO ByteString -> m ByteString
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO ByteString
B.getContents

-- | Lifted 'B.putStr'
putStr :: MonadIO m => ByteString -> m ()
putStr :: ByteString -> m ()
putStr = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> (ByteString -> IO ()) -> ByteString -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> IO ()
B.putStr

-- | Lifted 'B.interact'
interact :: MonadIO m => (ByteString -> ByteString) -> m ()
interact :: (ByteString -> ByteString) -> m ()
interact = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ())
-> ((ByteString -> ByteString) -> IO ())
-> (ByteString -> ByteString)
-> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ByteString -> ByteString) -> IO ()
B.interact

-- | Lifted 'B.readFile'
readFile :: MonadIO m => FilePath -> m ByteString
readFile :: FilePath -> m ByteString
readFile = IO ByteString -> m ByteString
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO ByteString -> m ByteString)
-> (FilePath -> IO ByteString) -> FilePath -> m ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FilePath -> IO ByteString
B.readFile

-- | Lifted 'B.writeFile'
writeFile :: MonadIO m => FilePath -> ByteString -> m ()
writeFile :: FilePath -> ByteString -> m ()
writeFile FilePath
fp = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> (ByteString -> IO ()) -> ByteString -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FilePath -> ByteString -> IO ()
B.writeFile FilePath
fp

-- | Lifted 'B.appendFile'
appendFile :: MonadIO m => FilePath -> ByteString -> m ()
appendFile :: FilePath -> ByteString -> m ()
appendFile FilePath
fp = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> (ByteString -> IO ()) -> ByteString -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FilePath -> ByteString -> IO ()
B.appendFile FilePath
fp

-- | Lifted 'B.hGetLine'
hGetLine :: MonadIO m => Handle -> m ByteString
hGetLine :: Handle -> m ByteString
hGetLine = IO ByteString -> m ByteString
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO ByteString -> m ByteString)
-> (Handle -> IO ByteString) -> Handle -> m ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle -> IO ByteString
B.hGetLine

-- | Lifted 'B.hGetContents'
hGetContents :: MonadIO m => Handle -> m ByteString
hGetContents :: Handle -> m ByteString
hGetContents = IO ByteString -> m ByteString
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO ByteString -> m ByteString)
-> (Handle -> IO ByteString) -> Handle -> m ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle -> IO ByteString
B.hGetContents

-- | Lifted 'B.hGet'
hGet :: MonadIO m => Handle -> Int -> m ByteString
hGet :: Handle -> Int -> m ByteString
hGet Handle
h = IO ByteString -> m ByteString
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO ByteString -> m ByteString)
-> (Int -> IO ByteString) -> Int -> m ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle -> Int -> IO ByteString
B.hGet Handle
h

-- | Lifted 'B.hGetSome'
hGetSome :: MonadIO m => Handle -> Int -> m ByteString
hGetSome :: Handle -> Int -> m ByteString
hGetSome Handle
h = IO ByteString -> m ByteString
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO ByteString -> m ByteString)
-> (Int -> IO ByteString) -> Int -> m ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle -> Int -> IO ByteString
B.hGetSome Handle
h

-- | Lifted 'B.hGetNonBlocking'
hGetNonBlocking :: MonadIO m => Handle -> Int -> m ByteString
hGetNonBlocking :: Handle -> Int -> m ByteString
hGetNonBlocking Handle
h = IO ByteString -> m ByteString
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO ByteString -> m ByteString)
-> (Int -> IO ByteString) -> Int -> m ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle -> Int -> IO ByteString
B.hGetNonBlocking Handle
h

-- | Lifted 'B.hPut'
hPut :: MonadIO m => Handle -> ByteString -> m ()
hPut :: Handle -> ByteString -> m ()
hPut Handle
h = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> (ByteString -> IO ()) -> ByteString -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle -> ByteString -> IO ()
B.hPut Handle
h

-- | Lifted 'B.hPutNonBlocking'
hPutNonBlocking :: MonadIO m => Handle -> ByteString -> m ByteString
hPutNonBlocking :: Handle -> ByteString -> m ByteString
hPutNonBlocking Handle
h = IO ByteString -> m ByteString
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO ByteString -> m ByteString)
-> (ByteString -> IO ByteString) -> ByteString -> m ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle -> ByteString -> IO ByteString
B.hPutNonBlocking Handle
h

-- | Lifted 'B.hPutStr'
hPutStr :: MonadIO m => Handle -> ByteString -> m ()
hPutStr :: Handle -> ByteString -> m ()
hPutStr Handle
h = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> (ByteString -> IO ()) -> ByteString -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle -> ByteString -> IO ()
B.hPutStr Handle
h