1{-# LANGUAGE CPP #-} 2-- | The standard @openFile@ call on Windows causing problematic file locking 3-- in some cases. This module provides a cross-platform file reading API 4-- without the file locking problems on Windows. 5-- 6-- This module /always/ opens files in binary mode. 7-- 8-- @readChunk@ will return an empty @ByteString@ on EOF. 9module Data.Streaming.FileRead 10 ( ReadHandle 11 , openFile 12 , closeFile 13 , readChunk 14 ) where 15 16#if WINDOWS 17 18import System.Win32File 19 20#else 21 22import qualified System.IO as IO 23import qualified Data.ByteString as S 24import Data.ByteString.Lazy.Internal (defaultChunkSize) 25 26newtype ReadHandle = ReadHandle IO.Handle 27 28openFile :: FilePath -> IO ReadHandle 29openFile fp = ReadHandle `fmap` IO.openBinaryFile fp IO.ReadMode 30 31closeFile :: ReadHandle -> IO () 32closeFile (ReadHandle h) = IO.hClose h 33 34readChunk :: ReadHandle -> IO S.ByteString 35readChunk (ReadHandle h) = S.hGetSome h defaultChunkSize 36 37#endif 38