Tuesday, November 6, 2012

reading binary files in ruby

Let's say you have a binary file filled with a bunch of doubles:
File.open("file_name","r") do |file|
  while !file.eof?
    puts file.read(8).unpack('D')[0]
  end
end