From: Daniel Martin Date: 2006-07-19T02:13:30+09:00 Subject: Re: How can I parse binary files? "ChrisH" writes: > Looks like you need to investigate #unpack. > > In any case, Ruby Facets has a BinaryReader mixin > (http://facets.rubyforge.org/api/more/classes/BinaryReader.html) that > does the reading and upacking for you. Just mix it into File (or a > subclass of File) and you should be good to go... That's fine if you want to pull out each field in succession yourself, but BitStruct provides much more than that, by providing a DSL for packed-bit structures. Also, if you see my reply, you'll notice that he was in fact very close to getting what he wanted. Actually, going through this exercise has pointed up some features that I would like to add to BitStruct, since in many cases it almost but not quite completely was exactly what the poster wanted. It would be nice to have an easy, obvious, and supported way to define extra padding in a structure (as we needed to here). It would be nice to have an easier, supported syntax for reading a structure from a binary file. Finally, it would be nice to allow an easy way to define data wrappers, as was done with the date property.