[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Reading a zip file from a GET request without saving?

Arthur Christoph

5/6/2009 11:08:00 PM

All:
I am trying read zip file from HTTP GET request. One way to do it is by
saving the response body to a physical file first and then reading the
zip file to read the files inside the zip.

Is there a way to read the files inside directly without having to save
the zip file into a physical file first?

My current code:

Net::HTTP.start("clinicaltrials.gov") do |http|
resp = http.get("/ct2/results/download?id=15002A")
open("C:\\search_result.zip", "wb") do |file|
file.write(resp.body)
end
end

Zip::ZipFile.open("C:\\search_result.zip") do |zipfile|
xml = zipfile.file.read("search_result.xml")

end

Many thanks,
christoph
--
Posted via http://www.ruby-....

1 Answer

7stud --

5/7/2009 4:31:00 AM

0

Arthur Christoph wrote:
>
> Is there a way to read the files inside directly without having to save
> the zip file into a physical file first?
>

I couldn't figure out how to do that, but you can always use TempFile to
handle creating a unique name and then deleting the file automatically
when your program terminates.
--
Posted via http://www.ruby-....