Got the core functionality of download() working. The function now parses a completed table response and either returns the data to the terminal, or it writes to file and returns the data to the terminal.