File#each_byte returns only the first 300 bytes

N

Niko Schwarz

Hello, I have the most recent (rc10) version of rubyinstaller for
windows.
everything works fine, except this:
read_bytes returns in text files everything, but in binary files, only
the first 300 bytes.
the snippet i use is

s = 0
File.open(fileName) { |f|
f.each_byte { |ch|
ch > 127 or (fh[ch] += 1 and s += 1)
}

What am I doing wrong? Is it a bug? (hard to believe in such a basic
function).

best regards,

niko
 
H

Henrik Horneber

Niko said:
Hello, I have the most recent (rc10) version of rubyinstaller for
windows.
everything works fine, except this:
read_bytes returns in text files everything, but in binary files, only
the first 300 bytes.
the snippet i use is

s = 0
File.open(fileName) { |f|
f.each_byte { |ch|
ch > 127 or (fh[ch] += 1 and s += 1)
}

What am I doing wrong? Is it a bug? (hard to believe in such a basic
function).

I seem to remember you need to tell Ruby to open files in binary modes
on Windows , e.g.
File.open(fileName, "rb")

HTH

Henrik
 

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
474,164
Messages
2,570,901
Members
47,439
Latest member
elif2sghost

Latest Threads

Top