[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

need to fetch a zip file from url and unzip it

phil swenson

11/16/2006 4:25:00 AM

I"m aware of:

require 'open-uri'
zipFile = open(URL).read

but this pulls back a string... I need to pull back a zip file
(binary).

Any ideas?

thanks,
phil

3 Answers

Paul Lutus

11/16/2006 6:43:00 AM

0

phil.swenson@gmail.com wrote:

> I"m aware of:
>
> require 'open-uri'
> zipFile = open(URL).read
>
> but this pulls back a string... I need to pull back a zip file
> (binary).
>
> Any ideas?

Well since you are trying to unzip a ZIP file, I suggest you read about the
Zlib::Inflate class in your documentation.

Start here:

http://www.ruby-doc.org/core/classes/Zlib/In...

The above page shows this example:

def inflate(string)
zstream = Zlib::Inflate.new
buf = zstream.inflate(string)
zstream.finish
zstream.close
buf
end

--
Paul Lutus
http://www.ara...

phil swenson

11/16/2006 3:07:00 PM

0

Isn't Zlib for gzip? I'm trying to access a zip file.

To use ruby Zip for this, but I have a string, not a binary form the
> > require 'open-uri'
> > zipFile = open(URL).read

code...

not sure how to proceed.

thanks,

phil

Paul Lutus wrote:
> phil.swenson@gmail.com wrote:
>
> > I"m aware of:
> >
> > require 'open-uri'
> > zipFile = open(URL).read
> >
> > but this pulls back a string... I need to pull back a zip file
> > (binary).
> >
> > Any ideas?
>
> Well since you are trying to unzip a ZIP file, I suggest you read about the
> Zlib::Inflate class in your documentation.
>
> Start here:
>
> http://www.ruby-doc.org/core/classes/Zlib/In...
>
> The above page shows this example:
>
> def inflate(string)
> zstream = Zlib::Inflate.new
> buf = zstream.inflate(string)
> zstream.finish
> zstream.close
> buf
> end
>
> --
> Paul Lutus
> http://www.ara...

Jano Svitok

11/16/2006 3:27:00 PM

0

On 11/16/06, phil.swenson@gmail.com <phil.swenson@gmail.com> wrote:
> Isn't Zlib for gzip? I'm trying to access a zip file.
>
> To use ruby Zip for this, but I have a string, not a binary form the
> > > require 'open-uri'
> > > zipFile = open(URL).read
>
> code...
>
> not sure how to proceed.
>
> thanks,

The string you have is the content of the zip file. To make it a file
just write it to a file.
File.open(NAME, 'wb') {|f| f.write string}

You may want to try rubyzip.sf.net

I'm not sure but I think gzip and zip files use the same compression.