2012-08-06 20:31:50 +00:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
|
2012-08-07 13:49:21 +00:00
|
|
|
# stdlib
|
|
|
|
require 'stringio'
|
|
|
|
require 'zlib'
|
2012-08-06 20:31:50 +00:00
|
|
|
|
|
|
|
def inflate(data)
|
|
|
|
Zlib::Inflate.inflate(data)
|
|
|
|
end
|
|
|
|
|
2012-08-07 13:49:21 +00:00
|
|
|
def deflate(data)
|
|
|
|
Zlib::Deflate.deflate(data)
|
|
|
|
end
|
|
|
|
|
2012-08-06 20:31:50 +00:00
|
|
|
# there is not a difference for us, in these two
|
|
|
|
def inflate2(data)
|
|
|
|
zlib = Zlib::Inflate.new(15)
|
|
|
|
buff = zlib.inflate(data)
|
|
|
|
zlib.finish
|
|
|
|
zlib.close
|
|
|
|
buff
|
|
|
|
end
|
|
|
|
|
|
|
|
def load_dictionary(data)
|
|
|
|
data.split("\x00")
|
|
|
|
end
|
|
|
|
|
|
|
|
if $0 == __FILE__
|
|
|
|
abort("usage: %s <bin_file> ..." % __FILE__) unless (ARGV.length > 0)
|
|
|
|
|
|
|
|
ARGV.each do |arg|
|
|
|
|
file = File.open(arg)
|
|
|
|
|
2012-08-07 13:49:21 +00:00
|
|
|
z_data_io = StringIO.new(file.read())
|
|
|
|
data = inflate(z_data_io.read())
|
|
|
|
e_pos = deflate(data).bytesize()
|
|
|
|
z_data_io.seek(e_pos)
|
|
|
|
|
2012-08-06 20:31:50 +00:00
|
|
|
puts "data is:"
|
|
|
|
puts load_dictionary(data).map {|x| "\t#{x}" }
|
|
|
|
|
|
|
|
puts "dictionary stats:"
|
2012-08-07 13:49:21 +00:00
|
|
|
puts "\tcompressed size: %d" % deflate(data).bytesize()
|
2012-08-06 20:31:50 +00:00
|
|
|
puts "\tuncompressed size: %d" % data.bytesize()
|
2012-08-07 13:49:21 +00:00
|
|
|
|
|
|
|
buf = z_data_io.read()
|
|
|
|
puts "Read %d bytes\n" % buf.bytesize()
|
|
|
|
|
2012-08-06 20:31:50 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|