# Mechanize Download File w/o Loading it All in Memory

**URL:** <https://www.ruby-forum.com/t/mechanize-download-file-w-o-loading-it-all-in-memory/174524>\
**Category:** Ruby\
**Created:** [August 28, 2009, 5:07am UTC](https://www.ruby-forum.com/t/mechanize-download-file-w-o-loading-it-all-in-memory/174524 "2009-08-28T05:07:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nappin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f475e1/32.png) [@nappin](https://www.ruby-forum.com/u/nappin)\
**Post date:** [August 28, 2009, 5:07am UTC](https://www.ruby-forum.com/t/mechanize-download-file-w-o-loading-it-all-in-memory/174524/1 "2009-08-28T05:07:10Z")

</div>

Is there a way to get Mechanize to download a csv file, without loading  
it all into memory first? As I understand even if I used a pluggable  
parser, it will still download the whole file into memory before saving  
it to a file?

Thanks!

---

<div class="post-metadata">

**Author:** ![nappin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f475e1/32.png) [@nappin](https://www.ruby-forum.com/u/nappin)\
**Post date:** [August 28, 2009, 5:42am UTC](https://www.ruby-forum.com/t/mechanize-download-file-w-o-loading-it-all-in-memory/174524/2 "2009-08-28T05:42:23Z")

</div>

On Aug 27, 2009, at 20:07 , Raymond O’Connor wrote:

> Is there a way to get Mechanize to download a csv file, without  
> loading  
> it all into memory first? As I understand even if I used a pluggable  
> parser, it will still download the whole file into memory before  
> saving  
> it to a file?

I don’t actually know if this will solve your problem as I’ve not used  
it, but this looks like it is on the right track:

> require ‘rubygems’  
> require ‘mechanize’
> 
> agent = WWW::Mechanize.new  
> agent.pluggable\_parser.pdf = WWW::Mechanize::FileSaver  
> agent.get(‘[http://example.com/foo.pdf](http://example.com/foo.pdf)’)

then again, it might not. mechanize doesn’t sound like a very good  
tool to be using for csv’s in the first place as it can’t actually DO  
much with them. Why not use a more straightforward tool like curl?

---

<div class="post-metadata">

**Author:** ![nappin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f475e1/32.png) [@nappin](https://www.ruby-forum.com/u/nappin)\
**Post date:** [August 28, 2009, 11:27pm UTC](https://www.ruby-forum.com/t/mechanize-download-file-w-o-loading-it-all-in-memory/174524/3 "2009-08-28T23:27:26Z")

</div>

Ryan D. wrote:

> On Aug 27, 2009, at 20:07 , Raymond O’Connor wrote:
> 
> > Is there a way to get Mechanize to download a csv file, without  
> > loading  
> > it all into memory first? As I understand even if I used a pluggable  
> > parser, it will still download the whole file into memory before  
> > saving  
> > it to a file?
> 
> I don’t actually know if this will solve your problem as I’ve not used  
> it, but this looks like it is on the right track:
> 
> > require ‘rubygems’  
> > require ‘mechanize’
> > 
> > agent = WWW::Mechanize.new  
> > agent.pluggable\_parser.pdf = WWW::Mechanize::FileSaver  
> > agent.get(‘[http://example.com/foo.pdf](http://example.com/foo.pdf)’)
> 
> then again, it might not. mechanize doesn’t sound like a very good  
> tool to be using for csv’s in the first place as it can’t actually DO  
> much with them. Why not use a more straightforward tool like curl?

It’s a whole process just to get to the page where you can download the  
csv file. I have to log in to the site, request the file, etc. which  
is why I was hoping I could do it in mechanize
