Slurping an entire file in Windows

L

listrecv

A very neat and useful feature of Ruby is:
contents = File.read(filename)

Unfortunately, there's no simple way to do this for *binary* files in
OS's that differentiate (ie Windows). Or is there a similar method
which does the same in binary mode?

A simple workaround is to:
class IO
def self.readbin(filename)
self.class.open(filename, 'rb') { |f| f.read }
end
end

Could I suggest that the maintainers put it in the std-lib?
 
L

listrecv

Should be:

class IO
def self.readbin(filename)
self.open(filename, 'rb') { |f| f.read }
end
end
 
R

Robert Klemme

Should be:

class IO
def self.readbin(filename)
self.open(filename, 'rb') { |f| f.read }
end
end
Should be:

class IO
def self.readbin(filename)
open(filename, 'rb') { |f| f.read }
end
end

:)

robert
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top