Most simple usage of zlib or pr-zlib

Discussion in 'Ruby' started by Nicholas Wieland, Mar 9, 2011.

  1. 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
    Nicholas Wieland, Mar 9, 2011
    #1
    1. Advertising

  2. Nicholas Wieland

    Y. NOBUOKA Guest

    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,
    --
    NOBUOKA Yu
    http://www.vividcode.info/
    Y. NOBUOKA, Mar 9, 2011
    #2
    1. Advertising

  3. Nicholas Wieland

    Jeremy Bopp Guest

    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
    Jeremy Bopp, Mar 9, 2011
    #3
  4. 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
    Nicholas Wieland, Mar 10, 2011
    #4
  5. Nicholas Wieland

    Jeremy Bopp Guest

    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
    Jeremy Bopp, Mar 10, 2011
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. H.MuthuKumaraRajan
    Replies:
    3
    Views:
    427
    H.MuthuKumaraRajan
    Feb 4, 2004
  2. nagrik
    Replies:
    1
    Views:
    504
    Thomas J. Gritzan
    Jun 30, 2006
  3. xkenneth
    Replies:
    8
    Views:
    329
    Bruno Desthuilliers
    Feb 6, 2008
  4. Matthew Brett
    Replies:
    4
    Views:
    1,082
    Matthew Brett
    May 9, 2010
  5. Daniel Berger
    Replies:
    5
    Views:
    225
    Roger Pack
    Jun 21, 2009
Loading...

Share This Page