I am using Ruby's ZLib library to decompress a smallish (10k) gzip file (in memory using a StringIO class) and its taking approximately 2.5 seconds to decompress. Compressing the data takes ~100ms, so I don't understand why the decompression is taking magnitudes longer than the compress function.
My function takes a StringIO object (with the contents of the compressed data) and returns an array of (3 - where '3' is defined by the int_size parameter) byte integers, like:
def decompress(io, int_size = 3)
array = Array.new(262144)
i = 0
io.rewind
gz = Zlib::GzipReader.new(io)
until gz.eof?
buffer = gz.read(int_size)
array[i] = buffer.unpack('C*').inject { |r, n| r << 8 | n }
i += 1
end
array
end
The same file decompresses at the OSX command line in a blink of an eye.
Is there a faster way to decompress the file, or perhaps a faster library or a way to use the gzip on the local system to get this happening much faster than it is now?