Opened 4 years ago

Closed 4 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 Revisions:

Description

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 4 years ago by Tinctorius

  • Component changed from Compiler to Prelude

component = Prelude

comment:2 Changed 4 years ago by simonmar

  • Resolution set to invalid
  • Status changed from new to closed

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.