openFile and text mode vs. binary mode
Simon Marlow
simonmar@microsoft.com
Tue, 10 Jun 2003 10:33:53 +0100
Hi Folks,
On Windows systems, one has the option of opening files in text or
binary mode. Text mode does some simple translations: \n\r gets
translated to \n, and ^Z indicates the end of the file. Binary mode
does no translation.
We can think of this one particular kind of text translation, where
others might be UTF8, UTF16, and so on. Ultimately, having a flexible
framework for attaching text translations to Handles should be a goal
(and has been discussed before), but I'm going to ignore that for now.
The point of this message is to ask for opinions on an interface for
exposing text mode vs. binary mode to users of System.IO. This will
most likely be an interrim measure.
For a long time, GHC has had the following, in IOExts (and lately
GHC.Handle):
data IOModeEx=20
=3D BinaryMode IOMode
| TextMode IOMode
deriving (Eq, Read, Show)
openFileEx :: FilePath -> IOModeEx -> IO Handle
hSetBinaryMode :: Handle -> Bool -> IO ()
and files are opened in text mode by default (by openFile).
The question is: is this the interface that we want to expose from
System.IO? Personally I have two criticisms: openFileEx is not a
particularly descriptive name, and I don't see a reason for IOMode to be
nested inside IOModeEx. So I'd suggest this instead:
openBinaryFile :: FilePath -> IOMode -> IO Handle
hSetBinaryMode :: Handle -> Bool -> IO ()
I can see this discussion ballooning in several different directions,
which is fine. But I'm primarily looking for something simple that we
can use as an interrim measure for GHC 6.2.
Cheers,
Simon