From: Jim Date: 2008-02-01T20:24:57+09:00 Subject: Re: Newbie: working with binary files/extract png from a binary file On Jan 30, 7:29 pm, Adam Shelly wrote: > > > from the same docs: > "MatchData acts as an array. ... mtch[0] is equivalent to ... the > entire matched string. " > > so m.begin(0) returns the offset of the start of the matched string > (in this case, the start of the png header). Since the string > contains the contents of the whole file, the string offset is the same > as the file offset we need. > -Adam OK, it's really not that hard is it? input.read(N) read N bytes from the stream. From the spec we know PNG has an header (they call a signature) that is 8 bytes. Check it. If it's a PNG, read the chunks until IEND The only other thing is unpack("N"). From the docs it takes a string of 4 bytes and returns a Fixnum. Thanks again for the code. The file I'm extracting is a SketchUp 3d model, btw.