6677-- Portability : GHC
88--
9- -- Read and write streams and arrays to and from files specified by their paths
10- -- in the file system. Unlike the handle based APIs which can have a read/write
11- -- session consisting of multiple reads and writes to the handle, these APIs
12- -- are one shot read or write APIs. These APIs open the file handle, perform
13- -- the requested operation and close the handle. Thease are safer compared to
14- -- the handle based APIs as there is no possibility of a file descriptor
15- -- leakage.
16- --
17- -- > import qualified Streamly.Internal.FileSystem.FileIO as File
18- --
199
2010module Streamly.Internal.FileSystem.FileIO
2111 (
@@ -130,14 +120,17 @@ import qualified Streamly.Internal.FileSystem.Windows.File as File
130120-- Safe file reading
131121-------------------------------------------------------------------------------
132122
133- -- | @'withFile' name mode act@ opens a file with NoBuffering set on the handle
134- -- and passes the resulting handle to the computation @act@. The handle will be
135- -- closed on exit from 'withFile', whether by normal termination or by raising
136- -- an exception. If closing the handle raises an exception, then that
137- -- exception is raised by 'withFile' rather than any exception raised by 'act'.
123+ -- | @'withFile' name mode act@ opens a file and passes the resulting handle to
124+ -- the computation @act@. The handle is closed on exit from 'withFile', whether
125+ -- by normal termination or by raising an exception. If closing the handle
126+ -- raises an exception, then that exception is raised by 'withFile' rather than
127+ -- any exception raised by 'act'.
138128--
139- -- The file is opened without buffering as buffering can be controlled by the
140- -- streaming APIs.
129+ -- The file is opened in binary mode as encoding, decoding, and newline
130+ -- translation can be handled explicitly by the streaming APIs.
131+ --
132+ -- The file is opened without buffering as buffering can be controlled
133+ -- explicitly by the streaming APIs.
141134--
142135-- /Pre-release/
143136--
@@ -149,7 +142,7 @@ withFile file mode = S.bracketIO open hClose
149142 where
150143
151144 open = do
152- h <- File. openFile file mode
145+ h <- File. openBinaryFile file mode
153146 hSetBuffering h NoBuffering
154147 return h
155148
@@ -160,8 +153,11 @@ withFile file mode = S.bracketIO open hClose
160153-- handle raises an exception, then this exception will be raised by
161154-- 'usingFile'.
162155--
163- -- The file is opened without buffering as buffering can be controlled by the
164- -- streaming APIs.
156+ -- The file is opened in binary mode as encoding, decoding, and newline
157+ -- translation can be handled explicitly by the streaming APIs.
158+ --
159+ -- The file is opened without buffering as buffering can be controlled
160+ -- explicitly by the streaming APIs.
165161--
166162-- /Pre-release/
167163--
@@ -173,7 +169,7 @@ usingFile = UF.bracketIO open hClose
173169 where
174170
175171 open file = do
176- h <- File. openFile file ReadMode
172+ h <- File. openBinaryFile file ReadMode
177173 hSetBuffering h NoBuffering
178174 return h
179175
@@ -185,7 +181,7 @@ usingFile2 = UF.bracketIO before after
185181 where
186182
187183 before (x, file) = do
188- h <- File. openFile file ReadMode
184+ h <- File. openBinaryFile file ReadMode
189185 hSetBuffering h NoBuffering
190186 return (x, h)
191187
@@ -199,7 +195,7 @@ usingFile3 = UF.bracketIO before after
199195 where
200196
201197 before (x, y, z, file) = do
202- h <- File. openFile file ReadMode
198+ h <- File. openBinaryFile file ReadMode
203199 hSetBuffering h NoBuffering
204200 return (x, y, z, h)
205201
@@ -410,7 +406,7 @@ writeChunks :: (MonadIO m, MonadCatch m)
410406writeChunks path = Fold step initial extract final
411407 where
412408 initial = do
413- h <- liftIO (File. openFile path WriteMode )
409+ h <- liftIO (File. openBinaryFile path WriteMode )
414410 liftIO $ hSetBuffering h NoBuffering
415411 fld <- FL. reduce (FH. writeChunks h)
416412 `MC.onException` liftIO (hClose h)
0 commit comments