Download files in chunks

Prevents out-of-memory errors when downloading large files.
Merge pull request #16350 from thusoy/chunked-download

Download files in chunks