[rust-dev] Text Mode File Reading/Writing

Gil Cottle gcottle at redtown.org
Mon Jun 23 21:36:45 PDT 2014


Hello,

I'm looking through the File API at http://doc.rust-lang.org/std/io/ and I
don't see a way to open a file in binary-mode vs text-mode. It seems the
default is binary mode from tests that I've done. AFAIK, this only matters
on Windows since a carriage return would not be returned to the program in
text-mode on Windows.

It seems like FileAccess and FileMode are used to provide similar flags to
libc as are provided to fopen
http://www.cplusplus.com/reference/cstdio/fopen/ .

I'm looking at an implementation of md5sum in rust, but it doesn't have a
"text" option (equivalent fopen with mode "r" rather than "rb") that can be
implemented without using libc directly as far as I can tell. Is there a
way to do this with Rust?

If not, adding a flag would be useful for text file-writing/reading when
running on Windows, but it could also be a source of issues for people
trying to write binary/text data depending on the defaults. Any thoughts on
this?

Thanks,
Gil Cottle
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/rust-dev/attachments/20140624/3e3d277c/attachment.html>


More information about the Rust-dev mailing list