Most simple usage of zlib or pr-zlib

  • Thread starter Nicholas Wieland
  • Start date
N

Nicholas Wieland

HI *, I'm trying to unzip a file programmatically, and having lots of
difficulties.

ruby-1.9.2-p136 :009 > data = StringIO.new( open( 'test.zip', 'r' ).read )
=> #<StringIO:0x00000100c4c8a8>
ruby-1.9.2-p136 :010 > Zlib::GzipReader.new(data).read
Zlib::GzipFile::Error: not in gzip format

This is with both zlib in stdlib and pr-zlib from github.
What's strange is that the file seems in the right format:

[ngw@slicingupeyeballs:~]$ file test.zip
test.zip: Zip archive data, at least v1.0 to extract

What I need is a supersimple solution to extract a zip file and retain
the same directory structure, no more no less :)

Someone worked on something like this before ?

ngw
 
Y

Y. NOBUOKA

Hi,
ruby-1.9.2-p136 :009 > data = StringIO.new( open( 'test.zip', 'r' ).read )

I see that you want to read a ZIP format file, "test.zip". Right?
ruby-1.9.2-p136 :010 > Zlib::GzipReader.new(data).read
Zlib::GzipFile::Error: not in gzip format

However, you used Zlib::GzipReader. This class is used for not zip format,
but gzip format [1], so that error occurred.

One way to unzip a file is to use zipruby gem [2]. Please try it.

[1] http://www.ruby-doc.org/stdlib/libdoc/zlib/rdoc/classes/Zlib/GzipReader.html
[2] https://rubygems.org/search?utf8=✓&query=zipruby

Regards,
 
J

Jeremy Bopp

Unfortunately I'm on 1.9, but does archive-zip support both zip and gzip ?

No, it does not and will not. While the two technologies share the same
underlying compression codec, they each use the codec quite differently.
A ZIP file is an archive of one or more files and directories each
individually compressed, or possibly not compressed at all. A GZIP file
is a compressed version of a single file's contents. Those contents
could be, and often are, that of a TAR file which itself contains one or
more uncompressed files and directories; however, this method of
archival is completely different than that of a ZIP file.

If you want to extract an actual GZIP file, take a look at
Zlib::GzipReader included with the standard library:

http://rdoc.info/stdlib/zlib/1.9.2/Zlib/GzipReader

-Jeremy
 

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,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top