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

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top