{-# LANGUAGE UnicodeSyntax, NoImplicitPrelude #-} ------------------------------------------------------------------------------- -- | -- Module : Data.ByteString.SaferFileHandles -- Copyright : (c) 2010 Bas van Dijk -- License : BSD3 (see the file LICENSE) -- Maintainer : Bas van Dijk -- -- This module lifts the bytestring IO operations into the region monad. -- ------------------------------------------------------------------------------- module Data.ByteString.Lazy.SaferFileHandles ( hGetContents , hGet , hGetNonBlocking , hPut , hPutStr ) where ------------------------------------------------------------------------------- -- Imports ------------------------------------------------------------------------------- -- from base: import Data.Int ( Int ) -- from transformers: import Control.Monad.IO.Class ( MonadIO ) -- from bytestring: import qualified Data.ByteString.Lazy as B -- from regions: import Control.Monad.Trans.Region ( AncestorRegion ) -- from explicit-iomodes-bytestring: import qualified Data.ByteString.Lazy.ExplicitIOModes as E ( hGetContents , hGet , hGetNonBlocking , hPut , hPutStr ) -- from safer-file-handles: import System.IO.SaferFileHandles ( RegionalFileHandle , ReadModes, WriteModes ) import System.IO.SaferFileHandles.Unsafe ( wrap, wrap2 ) ------------------------------------------------------------------------------- -- ByteString I/O with regional file handles ------------------------------------------------------------------------------- -- | Wraps: @Data.ByteString.'B.hGetContents'@. hGetContents ∷ (pr `AncestorRegion` cr, MonadIO cr, ReadModes ioMode) ⇒ RegionalFileHandle ioMode pr → cr B.ByteString hGetContents = wrap E.hGetContents -- | Wraps: @Data.ByteString.'B.hGet'@. hGet ∷ (pr `AncestorRegion` cr, MonadIO cr, ReadModes ioMode) ⇒ RegionalFileHandle ioMode pr → Int → cr B.ByteString hGet = wrap2 E.hGet -- | Wraps: @Data.ByteString.'B.hGetNonBlocking'@. hGetNonBlocking ∷ (pr `AncestorRegion` cr, MonadIO cr, ReadModes ioMode) ⇒ RegionalFileHandle ioMode pr → Int → cr B.ByteString hGetNonBlocking = wrap2 E.hGetNonBlocking -- | Wraps: @Data.ByteString.'B.hPut'@. hPut ∷ (pr `AncestorRegion` cr, MonadIO cr, WriteModes ioMode) ⇒ RegionalFileHandle ioMode pr → B.ByteString → cr () hPut = wrap2 E.hPut -- | Wraps: @Data.ByteString.'B.hPutStr'@. hPutStr ∷ (pr `AncestorRegion` cr, MonadIO cr, WriteModes ioMode) ⇒ RegionalFileHandle ioMode pr → B.ByteString → cr () hPutStr = wrap2 E.hPutStr -- The End ---------------------------------------------------------------------