making the ruby unpacker have the same outcome as unpack.c

Unfortunately the ruby Zlib::ZStream internals are not really accessible
like the C functions
This commit is contained in:
Vincent Batts 2012-08-07 09:49:21 -04:00
parent 9ca686aa6f
commit 65bfba3f62
1 changed files with 17 additions and 6 deletions

View File

@ -1,13 +1,17 @@
#!/usr/bin/env ruby
$:.unshift(File.dirname(__FILE__))
require 'huffman.rb'
require 'thing.rb'
# stdlib
require 'stringio'
require 'zlib'
def inflate(data)
Zlib::Inflate.inflate(data)
end
def deflate(data)
Zlib::Deflate.deflate(data)
end
# there is not a difference for us, in these two
def inflate2(data)
zlib = Zlib::Inflate.new(15)
@ -27,14 +31,21 @@ if $0 == __FILE__
ARGV.each do |arg|
file = File.open(arg)
z_data = file.read()
data = inflate(z_data)
z_data_io = StringIO.new(file.read())
data = inflate(z_data_io.read())
e_pos = deflate(data).bytesize()
z_data_io.seek(e_pos)
puts "data is:"
puts load_dictionary(data).map {|x| "\t#{x}" }
puts "dictionary stats:"
puts "\tcompressed size: %d" % z_data.bytesize()
puts "\tcompressed size: %d" % deflate(data).bytesize()
puts "\tuncompressed size: %d" % data.bytesize()
buf = z_data_io.read()
puts "Read %d bytes\n" % buf.bytesize()
end
end