Forum: Ruby on Rails Read remote zip

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.
9c473e546ce5c80e6f39d7e0502b5561?d=identicon&s=25 Rob Redmon (rredmon)
on 2009-04-08 03:36
(Received via mailing list)
I'd like to decompress the contents of:
http://host.com/file.zip

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


Rob
Aafa8848c4b764f080b1b31a51eab73d?d=identicon&s=25 Phlip (Guest)
on 2009-04-08 05:55
(Received via mailing list)
RobR wrote:

> I'd like to decompress the contents of:
> 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.
9c473e546ce5c80e6f39d7e0502b5561?d=identicon&s=25 Rob Redmon (rredmon)
on 2009-04-08 16:19
(Received via mailing list)
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!
This topic is locked and can not be replied to.