Forum: Ruby Reading a zip file from a GET request without saving?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
6fa5d4e69b27b9803304d703170800c8?d=identicon&s=25 Arthur Christoph (artchrst)
on 2009-05-07 01:07
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
54404bcac0f45bf1c8e8b827cd9bb709?d=identicon&s=25 7stud -- (7stud)
on 2009-05-07 06:30
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.
This topic is locked and can not be replied to.