[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Reading and parsing a binary file

EdUarDo

6/29/2006 10:15:00 AM

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[i][2..(block[0].length - 1)]
puts s
i = i.next
end
end
3 Answers

EdUarDo

6/29/2006 10:57:00 AM

0

> 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.

Victal

11/17/2010 5:18:00 PM

0

Anne G wrote:
> Le 17/11/10 05:08, Victal a ?crit :
>
>> au moins nous autres
>
> Eh ! que j'avais pas h?te de lire votre avis sur la question !
>
> Je suis pas d??ue : b?tise crasse et fanfaronnade approximative.
> C'est votre marque de commerce.

Google est votre ami

Tapez: ANGLICISMES, CANADIANISMES ET MOTS FOLKLORIQUES


Anne G

11/17/2010 5:42:00 PM

0

Le 17/11/10 10:17, Victal a ?crit :
> Anne G wrote:
>> Le 17/11/10 05:08, Victal a ?crit :
>>
>>> au moins nous autres
>>
>> Eh ! que j'avais pas h?te de lire votre avis sur la question !
>>
>> Je suis pas d??ue : b?tise crasse et fanfaronnade approximative.
>> C'est votre marque de commerce.
>
> Google est votre ami
>
> Tapez: ANGLICISMES, CANADIANISMES ET MOTS FOLKLORIQUES

Je disais que votre r?ponse ?tait celle de quelqu'un qui ne conna?t ni
sa langue, ni la mani?re dont elle a ?volu? dans diverses parties du monde.

Je disais que votre science googlesque est ? la limite du grotesque.

Je disais que vous votre message correspondait totalement ? mes attentes
quant ? sa niaiserie, sa fatuit? et ? son inint?r?t.

Tapez (puisque, manifestement, hors de Google, vous ne savez rien) :

bol, partenaire, n?vrose, vote, p?tition, majorit?, opposition, d?river,
redingote, contredanse, paquebot, patient, romantique,...