Download files in chunks

Prevents out-of-memory errors when downloading large files.