# Reading a zip file from a GET request without saving?

**URL:** <https://www.ruby-forum.com/t/reading-a-zip-file-from-a-get-request-without-saving/167358>\
**Category:** Ruby\
**Created:** [May 7, 2009, 1:07am UTC](https://www.ruby-forum.com/t/reading-a-zip-file-from-a-get-request-without-saving/167358 "2009-05-07T01:07:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![artchrst](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e36b37/32.png) [@artchrst](https://www.ruby-forum.com/u/artchrst)\
**Post date:** [May 7, 2009, 1:07am UTC](https://www.ruby-forum.com/t/reading-a-zip-file-from-a-get-request-without-saving/167358/1 "2009-05-07T01:07:58Z")

</div>

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](http://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

---

<div class="post-metadata">

**Author:** ![artchrst](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e36b37/32.png) [@artchrst](https://www.ruby-forum.com/u/artchrst)\
**Post date:** [May 7, 2009, 6:30am UTC](https://www.ruby-forum.com/t/reading-a-zip-file-from-a-get-request-without-saving/167358/2 "2009-05-07T06:30:57Z")

</div>

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.
