From: Gavin Sinclair Date: 2003-09-08T13:30:21+09:00 Subject: Re: Read files at the byte level - how to? > Hi All, > > I want to use Ruby to compare two Zip files to test whether they are > identical. Accordingly, I want to read at the byte level, but I only > see methods to read strings, i.e. gets, readline and readlines. > > Is there a way to do what I want to do? Is there an example somewhere > on the Web? To get the whole file in one string: bytes = File.open("filename", "rb") { |file| file.read } Sadly, you can't do: bytes = File.read("filename", "rb") # File::read assumes text mode Anyway, "bytes" is now a string with the whole file in it. You can, of course, read a certain number of bytes with "file.read(1024)" for instance. Sorry for any misinformation in this reply; it's based on experience, not knowledge ;) Gavin