unpack("m*").pack("m")
gobbles up some characters. Here's an old snippet I used in the past to sniff out the version number: (Works for Ruby 1.8 and 2.0)
<span class="syntaxdefault"><br />module Example<br /><br /> def self</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">read_skp_version</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">file</span><span class="syntaxkeyword">)<br /> </span><span class="syntaxcomment"># Get the size of the file ID block;<br /> </span><span class="syntaxdefault">id_size </span><span class="syntaxkeyword">= </span><span class="syntaxdefault">IO</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">read</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">file</span><span class="syntaxkeyword">, </span><span class="syntaxdefault">1</span><span class="syntaxkeyword">, </span><span class="syntaxdefault">3</span><span class="syntaxkeyword">).</span><span class="syntaxdefault">unpack</span><span class="syntaxkeyword">(</span><span class="syntaxstring">'C'</span><span class="syntaxkeyword">)[</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">] * </span><span class="syntaxdefault">2<br /> </span><span class="syntaxcomment"># => 28<br /><br /> # Get the size of the file version block;<br /> </span><span class="syntaxdefault">version_size </span><span class="syntaxkeyword">= </span><span class="syntaxdefault">IO</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">read</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">file</span><span class="syntaxkeyword">, </span><span class="syntaxdefault">1</span><span class="syntaxkeyword">, </span><span class="syntaxdefault">4 </span><span class="syntaxkeyword">+ </span><span class="syntaxdefault">id_size </span><span class="syntaxkeyword">+ </span><span class="syntaxdefault">3</span><span class="syntaxkeyword">).</span><span class="syntaxdefault">unpack</span><span class="syntaxkeyword">(</span><span class="syntaxstring">'C'</span><span class="syntaxkeyword">)[</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">] * </span><span class="syntaxdefault">2<br /> </span><span class="syntaxcomment"># => 20<br /><br /> # Get the version block data. This will be UTF-16LE encoded. Since Ruby 1.8<br /> # doesn't have the encoding methods we hack it by zapping out all the zero bytes<br /> # in the data string which will give us a regular ASCII string. This works<br /> # because we know the version string is within the ASCII range.<br /> </span><span class="syntaxdefault">version </span><span class="syntaxkeyword">= </span><span class="syntaxdefault">IO</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">read</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">file</span><span class="syntaxkeyword">, </span><span class="syntaxdefault">version_size</span><span class="syntaxkeyword">, </span><span class="syntaxdefault">4 </span><span class="syntaxkeyword">+ </span><span class="syntaxdefault">id_size </span><span class="syntaxkeyword">+ </span><span class="syntaxdefault">4</span><span class="syntaxkeyword">).</span><span class="syntaxdefault">gsub</span><span class="syntaxkeyword">(</span><span class="syntaxstring">"\x00"</span><span class="syntaxkeyword">,</span><span class="syntaxstring">""</span><span class="syntaxkeyword">)<br /> </span><span class="syntaxcomment"># => {15.1.106}<br /><br /> # Extract the version components.<br /> </span><span class="syntaxdefault">version</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">match</span><span class="syntaxkeyword">(/\{(\</span><span class="syntaxdefault">d</span><span class="syntaxkeyword">+)\.(\</span><span class="syntaxdefault">d</span><span class="syntaxkeyword">+)\.(\</span><span class="syntaxdefault">d</span><span class="syntaxkeyword">+)\}/).</span><span class="syntaxdefault">captures</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">map </span><span class="syntaxkeyword">{ |</span><span class="syntaxdefault">x</span><span class="syntaxkeyword">| </span><span class="syntaxdefault">x</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">to_i </span><span class="syntaxkeyword">}<br /> </span><span class="syntaxcomment"># => [15, 1, 106]<br /> </span><span class="syntaxdefault">end<br /><br />end </span><span class="syntaxcomment"># module<br /><br /># Example usage;<br /></span><span class="syntaxdefault">major</span><span class="syntaxkeyword">, </span><span class="syntaxdefault">minor</span><span class="syntaxkeyword">, </span><span class="syntaxdefault">revision </span><span class="syntaxkeyword">= </span><span class="syntaxdefault">Example</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">read_skp_version</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">path</span><span class="syntaxkeyword">)<br /> </span><span class="syntaxdefault"></span>