unzipping a gzipped string

A

Aaron Patterson

I'm trying to unzip a string I have in memory, but unfortunately I keep
getting a 'incorrect header check (Zlib::DataError)' when I try to unzip
the string.

The weird thing is that I can write the string out to a file, and unzip
it using gzip or even Zlib::GzipReader.

For example, using the same file, this works:

require 'zlib'

File.open(ARGV[0], 'r') { |f|
gz = Zlib::GzipReader.new(f)
puts gz.read
}

But this doesn't (it fails with 'incorrect header check'):

require 'zlib'

File.open(ARGV[0], 'r') { |f|
puts Zlib::Inflate.inflate(f.read)
}

Anyone have any hints? Thanks.

--Aaron
 
E

E. Mark Ping

I'm trying to unzip a string I have in memory, but unfortunately I keep
getting a 'incorrect header check (Zlib::DataError)' when I try to unzip
the string.

The weird thing is that I can write the string out to a file, and unzip
it using gzip or even Zlib::GzipReader.

For example, using the same file, this works:

require 'zlib'

File.open(ARGV[0], 'r') { |f|
gz = Zlib::GzipReader.new(f)
puts gz.read
}

But this doesn't (it fails with 'incorrect header check'):

require 'zlib'

File.open(ARGV[0], 'r') { |f|
puts Zlib::Inflate.inflate(f.read)
}

Anyone have any hints? Thanks.

A Gzip file has a header which includes the original filename. A
zlib-compressed string doesn't have the same header.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top