Processing a Binary File
Problem
You want to read binary data from a file, or write it to one.
Solution
Since Ruby strings make no distinction between binary and text data, processing a binary file needn't be any different than processing a text file. Just make sure you add "b" to your file mode when you open a binary file on Windows.
This code writes 10 bytes of binary data to a file, then reads it back:
open('binary', 'wb') do |f| (0..100).step(10) { |b| f << b.chr } end s = open('binary', 'rb') { |f| f.read } # => "