Read remote zip

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

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.

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!