Re: [rust-dev] Text Mode File Reading/Writing

2014-06-24 Thread Jonas Wielicki
On 24.06.2014 06:36, Gil Cottle wrote:
> 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?

For what its worth, I think the python way is the most clean way, with
respect to interoperability and platform independence. This is described
in a quite convoluted way in the [documentation for the open builtin][0].

They basically implement text mode themselves and don’t let the OS know
about it. On the OS side, they open all files in binary mode. In their
text mode implementation, they convert all newlines to '\n' while
reading and all '\n's to the platform newline while writing.

   [0]: https://docs.python.org/3/library/functions.html#open

p.s. Don’t let your self get distracted from the “deprecated” in the
mode table; this only refers to the mode string, not to the usage of
universal newlines using the `newline` keyword argument, described a bit
below the mode table.

> 
> Thanks,
> Gil Cottle
> 
> 
> 
> ___
> Rust-dev mailing list
> Rust-dev@mozilla.org
> https://mail.mozilla.org/listinfo/rust-dev
> 

___
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev


[rust-dev] Text Mode File Reading/Writing

2014-06-23 Thread Gil Cottle
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
___
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev