Opened 6 years ago

Closed 6 years ago

#5420 closed bug (invalid)

writeFile should use openBinaryFile

Reported by: Tinctorius Owned by:
Priority: normal Milestone:
Component: Prelude Version: 7.2.1
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


Apparently, I can't use writeFile to write binary data to a file in Windows:

Prelude Codec.Binary.Base64.String Data.Char> readFile "foo.txt"
  >>= return . decode . filter isAlphaNum >>= writeFile "foo.dat"
*** Exception: .../foo.dat: commitBuffer: invalid argument
  (character is not in the code page)

This is clearly because openFile opens the file with newline translation etc. (why would you ever want this by default? D:). writeFile does not mention this behaviour in its documentation.

Change History (2)

comment:1 Changed 6 years ago by Tinctorius

Component: CompilerPrelude

component = Prelude

comment:2 Changed 6 years ago by simonmar

Resolution: invalid
Status: newclosed

This is by design. If you want to write binary data, use openBinaryFile, or the Data.ByteString library instead.

Note: See TracTickets for help on using tickets.