Reading a zip file from a GET request without saving?

  • Thread starter Arthur Christoph
  • Start date
A

Arthur Christoph

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
 
7

7stud --

Arthur said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top