5

Possible Duplicate:
Downloading files without using Import

While attempting to answer my own question I realized that I don't know a way to simply download a binary file to a specified folder with Mathematica, bypassing any Import/Export processing.

One can Import as "Binary" but this uses several times the amount of memory that the file takes to store. Further, the entire file must be loaded into memory and then processed with Export. Is there some way to pipe or stream the file as it is downloaded directly to disk?

One solution would be if it were possible to directly OpenRead a URL and access the file as a stream, and/or read only a specified byte range within the file. Neither of these are apparently possible with the native tools. Perhaps a JLink program can be made that would allow similar functionality? What would that entail? (I don't write Java and therefore rarely use JLink.)

Mr.Wizard
  • 271,378
  • 34
  • 587
  • 1,371
  • 4
    Simple way? Use curl or wget :) – rm -rf Oct 03 '12 at 07:09
  • @rm I think I ended up with two questions in one here: (1) download to folder (2) stream-type access of internet resource. Do you think I should split them? – Mr.Wizard Oct 03 '12 at 07:28
  • I don't think so... they both are related in the sense that answering 2 will answer 1. Better to have it in one place. This is definitely an area where mma is lacking, but I'm actually ok with it (it can't toast my bread either... or can it?). I've been meaning to ask a related question myself — on how to output multipage pdfs... I've been fiddling with the "Pages" option in Export, but seems like I'm using the wrong syntax. Will ask if I make no headway in a few days – rm -rf Oct 03 '12 at 07:37
  • 1
    If you were ever considering writing Java then you'd have to ask what the benefit would be versus running wget or curl (out of the box so-to-speak) from within Mma using Run. The added advantage of wget is that you can download from URLs with cookies and logins etc. – Mike Honeychurch Oct 03 '12 at 08:38

0 Answers0