IO.write is not sufficient, since IO is a superclass of Socket etc. as well. File.write might be, but I'm not sure how much useful the write-at-once method is.
matz.
Thanks for your reply.
Since the entry level PC these days has about 512Mb of memory, it can be used for writing any file upto about a couple of hundred megabytes.
ie. Most.
It is also a convenience thing for nifty oneliners.
This RCR is for the smallest change that would be useful.
A much larger change (and hence potentially much more useful) would be...
Place read/write it on the URI class to lift and shift files in a network transparent manner.
Oneliner ftp/http/... client.
URI.write( "local.tgz",
URI.read(
"ftp://ftp.ruby-lang.org/pub/ruby/ruby-1.8.4.tar.gz"))
In which case it would make sense to also define a copy method.
URI.copy( "ftp://ftp.ruby-lang.org/pub/ruby/ruby-1.8.4.tar.gz",
"local.tgz")
Where the base URI would be your current work directory for ordinary scripts or as appropriate for CGI scripts.
I'm not sure URI is the appropriate class for that, perhaps a new subclass, or perhaps a mixin, I don't know.
The problem with something like
IO::read and
IO::write is that it's not really cross-platform safe because it would simply assume something like:
open(filename) { |ff| ff.read }
On Windows, that will *break* any binary file that is being read, and there's no way to force IO::read into binary mode.
IMO, this needs to be fixed first before considering something like this; otherwise, if you're wanting anything cross-platform, remember to use #open(filename, "wb") or #open(filename, "rb").
(The above posted by Austin Ziegler.)
That's OK. Make two more.
IO.read_binary IO.write_binary
JohnCarter
Actually Austin, just looking at the io.c code what you are asking is in fact a seperate RCR. You should create one if you want that.
matz.
Thanks for your reply.
Since the entry level PC these days has about 512Mb of memory, it can be used for writing any file upto about a couple of hundred megabytes.
ie. Most.
It is also a convenience thing for nifty oneliners.
This RCR is for the smallest change that would be useful.
A much larger change (and hence potentially much more useful) would be...
Place read/write it on the URI class to lift and shift files in a network transparent manner.
Oneliner ftp/http/... client.
In which case it would make sense to also define a copy method.
Where the base URI would be your current work directory for ordinary scripts or as appropriate for CGI scripts.
I'm not sure URI is the appropriate class for that, perhaps a new subclass, or perhaps a mixin, I don't know.
The problem with something like IO::read and IO::write is that it's not really cross-platform safe because it would simply assume something like:
On Windows, that will *break* any binary file that is being read, and there's no way to force IO::read into binary mode.
IMO, this needs to be fixed first before considering something like this; otherwise, if you're wanting anything cross-platform, remember to use #open(filename, "wb") or #open(filename, "rb").
(The above posted by Austin Ziegler.)
That's OK. Make two more.
IO.read_binary IO.write_binary
JohnCarter
Actually Austin, just looking at the io.c code what you are asking is in fact a seperate RCR. You should create one if you want that.