[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

unzipping a gzipped string

Aaron Patterson

8/22/2006 5:46:00 AM

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


3 Answers

Erik Veenstra

8/22/2006 7:30:00 AM

0

You might have to use binary files.

File.open(ARGV[0], 'rb')

Windows differentiates between binary and text files.

gegroet,
Erik V. - http://www.erikve...


Aaron Patterson

8/22/2006 3:38:00 PM

0

On Tue, Aug 22, 2006 at 04:30:01PM +0900, Erik Veenstra wrote:
> You might have to use binary files.
>
> File.open(ARGV[0], 'rb')
>
> Windows differentiates between binary and text files.
>
> gegroet,
> Erik V. - http://www.erikve...

I'm on OS X. I tried it with 'rb', but still get the same error.

--Aaron


emarkp

8/22/2006 5:01:00 PM

0

In article <20060822054708.GA8197@eviladmins.lan>,
Aaron Patterson <aaron_patterson@speakeasy.net> wrote:
>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.
--
Mark Ping
emarkp@soda.CSUA.Berkeley.EDU