writeToFile method
Downloads the object into file and returns its size in bytes.
The bytes go to a new file next to file (<file>.<random>.part), which is renamed to file once the
download is complete, replacing a file already there. When the download fails, the partial file is
deleted, file is left untouched and the error is rethrown. The directory of file must exist.
Implementation
Future<int> writeToFile(File file) => writeStreamToFile(openRead(), file);