Reading and parsing a binary file

  • Thread starter Eduardo Yáñez Parareda
  • Start date
E

Eduardo Yáñez Parareda

Hi all, in this code I read the content of a binary file which has blocks of data
separated for 'stream' and 'endstream' literals.

In buffer variable I pretend to put that blocks of data, and I get them, but I
don't know why buffer is not an Array of Strings instead of an Array of Arrays!.
When I ask for the class of buffer[0] it says me it's an Array, but I think it
should be a String.


File.open(ARGV[0], 'rb') do |file|
buffer = file.read.scan(/stream(.*?)endstream/m)
i = 0
buffer.each do |block|
s = block[2..(block[0].length - 1)]
puts s
i = i.next
end
end
 
E

Eduardo Yáñez Parareda

When I ask for the class of buffer[0] it says me it's an Array, but I
think it
should be a String.

I'm going to answer to myself, if regular expression specify groups with () scan returns
an array of arrays.
 

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
473,774
Messages
2,569,598
Members
45,157
Latest member
MercedesE4
Top