how to read binary file with char 0x1A

H

hsun

Hi,

I tried to read a binary file with a char '0x1A' (EOF on window I guess).=
=20
The method

File::each_byte stops at this char.=20

How can get it to read the whole file? Is there a binary mode for file op=
eration?

Thanks
 
E

Eric Hodel

Hi,

I tried to read a binary file with a char '0x1A' (EOF on window I
guess). The method

File::each_byte stops at this char.
How can get it to read the whole file? Is there a binary mode for
file operation?

File.open name, 'rb' do |fp|
# ...
end

PS: File::each_byte references a class method. You meant
File#each_byte.
 
W

William James

hsun said:
Hi,

I tried to read a binary file with a char '0x1A' (EOF on window I guess).
The method

File::each_byte stops at this char.

How can get it to read the whole file? Is there a binary mode for file operation?

Thanks

contents = open(filename, "rb") { |f| f.read }
 
S

SHIGETOMI, Takuhiko

hello.
contents = open(filename, "rb") { |f| f.read }

see also: IO.binmode

q2hdp://void/3d/universe/milky-way-galaxy/orion-arm/sol-solar-system/
3rd-planet/fareast/jp/tky/shigetomi.takuhiko.5618
 
B

Brian Schröder

=20
On 31 Aug 2005, at 21:24, hsun wrote:
=20
=20
File.open name, 'rb' do |fp|
# ...
end
=20
PS: File::each_byte references a class method. You meant
File#each_byte.
=20

That is one of the things that I did not understand for a long time,
because File#each_byte is valid ruby, a constant and a comment, and I
did not get that it is a way to say "the method of a file instance".

So I just wanted to pop in here and say:=20

File#each means each is a method of a File instance

maybe that helps someone with the same confusion I had ;-)

regards,

Brian

--=20
http://ruby.brian-schroeder.de/

Stringed instrument chords: http://chordlist.brian-schroeder.de/
 
A

Ara.T.Howard

Hi,

I tried to read a binary file with a char '0x1A' (EOF on window I guess). The
method

File::each_byte stops at this char.
How can get it to read the whole file? Is there a binary mode for file
operation?

Thanks

open(path, 'rb') do |f|
...
end

hth.

-a
--
===============================================================================
| email :: ara [dot] t [dot] howard [at] noaa [dot] gov
| phone :: 303.497.6469
| Your life dwells amoung the causes of death
| Like a lamp standing in a strong breeze. --Nagarjuna
===============================================================================
 

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

Forum statistics

Threads
474,177
Messages
2,570,953
Members
47,507
Latest member
codeguru31

Latest Threads

Top