# Read remote zip

**URL:** <https://www.ruby-forum.com/t/read-remote-zip/164992>\
**Category:** Rails\
**Created:** [April 8, 2009, 3:36am UTC](https://www.ruby-forum.com/t/read-remote-zip/164992 "2009-04-08T03:36:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![robredford](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/7ea924/32.png) [@robredford](https://www.ruby-forum.com/u/robredford)\
**Post date:** [April 8, 2009, 3:36am UTC](https://www.ruby-forum.com/t/read-remote-zip/164992/1 "2009-04-08T03:36:07Z")

</div>

I’d like to decompress the contents of:  
[http://host.com/file.zip](http://host.com/file.zip)

in memory without having to download the file (e.g. `wget`) first.  
Suggestions?

Rob

---

<div class="post-metadata">

**Author:** ![robredford](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/7ea924/32.png) [@robredford](https://www.ruby-forum.com/u/robredford)\
**Post date:** [April 8, 2009, 5:55am UTC](https://www.ruby-forum.com/t/read-remote-zip/164992/2 "2009-04-08T05:55:21Z")

</div>

RobR wrote:

> I’d like to decompress the contents of:  
> [http://host.com/file.zip](http://host.com/file.zip)
> 
> in memory without having to download the file (e.g. `wget`) first.  
> Suggestions?

“Without having to download the file first” is an example of “premature  
optimization”. It is the root of all evil.

On any OS configured to be a server (as opposed to a wrist watch, for  
example)  
all memory and files map each other virtually. If you Net::HTTP read()  
that file  
to a file location, the OS will generally reserve a slot on the hard  
drive, then  
put the file into its matching memory location.

In the next split microsecond, your code reads that file and unzips it,  
using  
only the memory image. If you then delete the file, it may never reach  
the hard  
drive.

By that analysis, if you write simple code that downloads the file and  
hits it  
with common tools, you can finish your feature faster. However, there  
are also  
situations where you _don’t_ know which option is faster.

Write the simpler code anyway, and then profile it to identify the real  
bottlenecks. They are invariably _not_ the places you would have  
guessed.

---

<div class="post-metadata">

**Author:** ![robredford](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/7ea924/32.png) [@robredford](https://www.ruby-forum.com/u/robredford)\
**Post date:** [April 8, 2009, 4:19pm UTC](https://www.ruby-forum.com/t/read-remote-zip/164992/3 "2009-04-08T16:19:47Z")

</div>

Those are good points.

For now, I whipped up something simple which basically:  
begin  
`wget #{url}`  
`unzip #{localfilename}`  
# do stuff with file (FasterCSV)  
rescue  
ensure  
# delete local files  
end

I don’t like relying on `` but sometimes it’s just too easy to pass  
up.  
My original message was trying to avoid `wget url`

Thanks!
