reading binary data stops unexpectedly

Discussion in 'Ruby' started by Gonzalo Rubio, Mar 5, 2006.

  1. i'm trying to parse a binary file that simply contains Wav files one
    after the other packed with an arbitrary header that points where one
    file begins and the lenght of it.
    The case is that i want to ignore decomposing the header and just dump
    each file as i encounter the Wav headers, but Ruby stops reading data
    unexpectedly.

    in a nutshell, my code goes like this:
    File.open('sound.dat', 'r').each_byte do |byte|
    #...stuff to process the data...
    end

    The block exits at 15864 bytes without throwing any errors. I even tried
    reading the whole file to memory and it just loads those same 15864
    bytes (and it's a 190MiB file!!!)

    Is this a known Ruby bug? am i doing something wrong?

    thanks in advance,
    /gonchuki

    --
    Posted via http://www.ruby-forum.com/.
     
    Gonzalo Rubio, Mar 5, 2006
    #1
    1. Advertising

  2. Gonzalo Rubio wrote:

    > in a nutshell, my code goes like this:
    > File.open('sound.dat', 'r').each_byte do |byte|
    > #...stuff to process the data...
    > end


    open('sound.dat', 'rb')


    lopex
     
    Marcin Mielżyński, Mar 5, 2006
    #2
    1. Advertising

  3. Marcin Mielżyński wrote:
    > Gonzalo Rubio wrote:
    >
    >> in a nutshell, my code goes like this:
    >> File.open('sound.dat', 'r').each_byte do |byte|
    >> #...stuff to process the data...
    >> end

    >
    > open('sound.dat', 'rb')
    >
    >
    > lopex


    nice!

    i just couldn't find it in the pickaxe 2 and forgot that ruby handles
    file open modes just like in C

    thanks for your help.

    --
    Posted via http://www.ruby-forum.com/.
     
    Gonzalo Rubio, Mar 5, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Art Werschulz
    Replies:
    0
    Views:
    677
    Art Werschulz
    Dec 3, 2003
  2. Frederic Wenzel

    pyserial problem: script stops reading

    Frederic Wenzel, Sep 9, 2006, in forum: Python
    Replies:
    0
    Views:
    301
    Frederic Wenzel
    Sep 9, 2006
  3. Frederic Wenzel

    pyserial problem: script stops reading

    Frederic Wenzel, Sep 9, 2006, in forum: Python
    Replies:
    0
    Views:
    271
    Frederic Wenzel
    Sep 9, 2006
  4. elitehunter99
    Replies:
    0
    Views:
    458
    elitehunter99
    Oct 17, 2006
  5. ChrisC
    Replies:
    11
    Views:
    3,090
    ChrisC
    Feb 7, 2007
Loading...

Share This Page