module Pipes.Safe.Prelude (
withFile,
readFile,
writeFile
) where
import Control.Monad.IO.Class (MonadIO(liftIO))
import Pipes (Producer', Consumer')
import Pipes.Safe (bracket, MonadSafe)
import qualified Pipes.Prelude as P
import qualified System.IO as IO
import Prelude hiding (readFile, writeFile)
withFile :: (MonadSafe m) => FilePath -> IO.IOMode -> (IO.Handle -> m r) -> m r
withFile file ioMode = bracket (liftIO $ IO.openFile file ioMode) (liftIO . IO.hClose)
readFile :: (MonadSafe m) => FilePath -> Producer' String m ()
readFile file = withFile file IO.ReadMode P.fromHandle
writeFile :: (MonadSafe m) => FilePath -> Consumer' String m r
writeFile file = withFile file IO.WriteMode P.toHandle