ruby - Stop reading from file when it can't read anymore using BinData -


currently i'm using bindata gem parse binary file format. works fine, except i'm not sure stop. file divided properties read using bindata records. there can anywhere between 16 , 18 properties (depending on file takes). so, if this:

16.times{     # parse data property. } 

that works fine when there 16 properties, however, if bump 17 following error.

'readbytes': end of file reached (eoferror) 

my question is, how can avoid 16 times , have read until reads properties can, stops when reaches end of file error.

from examples/tcp_ip.rb:

  class pcapfile < bindata::record     endian :little      struct :head       uint32 :magic       uint16 :major       uint16 :minor       int32  :this_zone       uint32 :sig_figs       uint32 :snaplen       uint32 :linktype     end      array :records, :read_until => :eof       uint32 :ts_sec       uint32 :ts_usec       uint32 :incl_len       uint32 :orig_len       string :data, :length => :incl_len     end   end 

the approach taken in example tell bindata there array of records, , let them read them all.


Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -