{-# LANGUAGE NoImplicitPrelude #-}
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)
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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