Piping binary files

I want to pipe a binary file through a Ruby script. I have tried

while (b = STDIN.getc)
STDOUT.putc(b)
end

and it works with text files but corrupts an mp3 file. STDIN.binmode did
not help. I can’t find read and write methods of the IO class that work
with binary files. What am I missing? Thanks.

Bazsl wrote:

Ignore my question. I made a dumb mistake.