1 # Part of the zip-doc suite
2 # By Stian Haklev (shaklev@gmail.com), 2007
3 # Released under MIT and GPL licenses
5 # Just a few utility functions that are used in several places
6 # I started out with having these as extensions of String and IO, but
7 # I guess that's not very nice in a library? I keep the pop though -
8 # cannot believe it isn't standard.
11 def self.unpack(string)
12 return string.unpack('H32V4' * (string.size/32))
15 def self.pack(md5, bstart, bsize, start, size)
16 return [md5, bstart, bsize, start, size].pack('H32V4')
19 def self.md5subset(four)
20 sprintf("%d", "0x" + four[0..3]).to_i
23 def self.writeloc(file, text, offset)
28 def self.readloc(file, size, offset)
33 def self.strip_whitespace(txt)
34 return txt.gsub(/\t/, " ").gsub(' ',' ').gsub("\n", '')
41 self.slice!(-number..-1)