Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Most simple usage of zlib or pr-zlib

Reply
Thread Tools

Most simple usage of zlib or pr-zlib

 
 
Nicholas Wieland
Guest
Posts: n/a
 
      03-09-2011
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

 
Reply With Quote
 
 
 
 
Y. NOBUOKA
Guest
Posts: n/a
 
      03-09-2011
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/libdo...zipReader.html
[2] https://rubygems.org/search?utf8=%E2...&query=zipruby

Regards,
--
NOBUOKA Yu
http://www.vividcode.info/

 
Reply With Quote
 
 
 
 
Jeremy Bopp
Guest
Posts: n/a
 
      03-09-2011
On 3/9/2011 06:14, Y. NOBUOKA wrote:
> One way to unzip a file is to use zipruby gem [2]. Please try it.


You might also want to take a look at the archive-zip gem:

http://rubygems.org/gems/archive-zip

Support for Ruby 1.9 is still in the works, but it should do what you
want with minimal effort otherwise.

-Jeremy

 
Reply With Quote
 
Nicholas Wieland
Guest
Posts: n/a
 
      03-10-2011
On 2011-03-09 15:36:38 +0100, Jeremy Bopp said:

> On 3/9/2011 06:14, Y. NOBUOKA wrote:
>> One way to unzip a file is to use zipruby gem [2]. Please try it.

>
> You might also want to take a look at the archive-zip gem:
>
> http://rubygems.org/gems/archive-zip
>
> Support for Ruby 1.9 is still in the works, but it should do what you
> want with minimal effort otherwise.


Thank you guys, I solved with zipruby.
Unfortunately I'm on 1.9, but does archive-zip support both zip and gzip ?

ngw

 
Reply With Quote
 
Jeremy Bopp
Guest
Posts: n/a
 
      03-10-2011
On 03/09/2011 06:50 PM, Nicholas Wieland wrote:
> 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
zlib.decompress fails, zlib.decompressobj succeeds - bug or feature? Matthew Brett Python 4 05-09-2010 09:19 PM
[ANN] pr-zlib 1.0.0 - A Pure Ruby zlib library Daniel Berger Ruby 5 06-21-2009 02:07 AM
What is the most simple, quicket, yet most powerful pythonWeb-Framework? xkenneth Python 8 02-06-2008 08:19 AM
zlib APIs usage problem in C++ program nagrik C++ 1 06-29-2006 11:11 PM
Invoking the Constructor of the Top Most Class in the Hierarchy from the Bottom most class H.MuthuKumaraRajan Java 3 02-04-2004 01:33 PM



Advertisments