Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

RFC: Updates to IO, IOString #1424

Merged
merged 3 commits into from
Oct 23, 2012
Merged

Conversation

kmsquire
Copy link
Member

In the original versions of read(s::GZipStream, ::Type{Char}) and write(s::GZipStream, Char) in #1355, Jeff suggested generalizing the functions so they work with all IO streams.

Edit: removed error message, fixed by Jameson's comment below.

Edit: The read and write methods above work, but don't quite go far enough. So, additionally, this patch

  • rearraged io.jl, so that all functions operating on abstract IO types are collected together. IOStream is located below. This makes it easier to see what needs to be implemented for IO subtypes
  • promotes each_line/EachLine to work with generic IO types
  • adds seek_end, position, truncate, eof, and close methods to IOString, to make it a (nearly) fully functional IO class
  • adds a bytestring method to IOString, so that its contents can easily be converted to a string

The bytestring(io::IOString) method isn't (yet) a replacement for memio(), since it copies the data. This is actually necessary, currently, because utf8 string written to IOString are converted to disk format (cf. the original read/write functions above). It may be worthwhile NOT to do so for IOString.

@vtjnash
Copy link
Member

vtjnash commented Oct 22, 2012

on line 271 error("write(IO, Char): illegal character $(uint(c))"), the $ interpolation macro hasn't been defined yet in the bootstrap sequence. Instead, writing it something like error("write(IO, Char): illegal character"*string(uint(c))) should resolve the error

@kmsquire
Copy link
Member Author

Perfect--thanks Jameson, it works!

@JeffBezanson
Copy link
Member

It seems to me the worst that can happen in writing a utf8 string is canonicalization. I think it would be ok to write a UTF8String to an IOString and get back slightly different bytes on reading, as long as valid characters remain the same.

JeffBezanson added a commit that referenced this pull request Oct 23, 2012
RFC: Updates to IO, IOString
@JeffBezanson JeffBezanson merged commit 543e84e into JuliaLang:master Oct 23, 2012
JeffBezanson added a commit that referenced this pull request Oct 27, 2012
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants