openFile and text mode vs. binary mode

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 = 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

On Tue, Jun 10, 2003 at 10:33:53AM +0100, Simon Marlow wrote:
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
Perhaps openFileAs? openBinaryFile sounds a bit like it would only open it as a binary, whereas in fact it actually gives you the option of opening it either as binary or as text. -- David Roundy http://www.abridgegame.org
participants (2)
-
David Roundy
-
Simon Marlow