{-# LANGUAGE CPP #-}
module Data.Streaming.FileRead
( ReadHandle
, openFile
, closeFile
, readChunk
) where
#if WINDOWS
import System.Win32File
#else
import qualified System.IO as IO
import qualified Data.ByteString as S
import Data.ByteString.Lazy.Internal (defaultChunkSize)
newtype ReadHandle = ReadHandle IO.Handle
openFile :: FilePath -> IO ReadHandle
openFile :: FilePath -> IO ReadHandle
openFile FilePath
fp = Handle -> ReadHandle
ReadHandle (Handle -> ReadHandle) -> IO Handle -> IO ReadHandle
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
`fmap` FilePath -> IOMode -> IO Handle
IO.openBinaryFile FilePath
fp IOMode
IO.ReadMode
closeFile :: ReadHandle -> IO ()
closeFile :: ReadHandle -> IO ()
closeFile (ReadHandle Handle
h) = Handle -> IO ()
IO.hClose Handle
h
readChunk :: ReadHandle -> IO S.ByteString
readChunk :: ReadHandle -> IO ByteString
readChunk (ReadHandle Handle
h) = Handle -> Int -> IO ByteString
S.hGetSome Handle
h Int
defaultChunkSize
#endif