INNER CODE UNIT · Python
save_and_check
kblin/ncbi-genome-download · ncbi_genome_download/core.py:661
def save_and_check(response, local_file, expected_checksum):
"""Save the content of an http response and verify the checksum matches."""
logger = logging.getLogger("ncbi-genome-download")
with open(local_file, 'wb') as handle:
for chunk in response.iter_content(4096):
handle.write(chunk)
actual_checksum = md5sum(local_file)
if actual_checksum != expected_checksum:
logger.error('Checksum mismatch for %r. Expected %r, got %r',
local_file, expected_checksum, actual_checksum)
return False
return True
def create_symlink(local_file, symlink_path):
"""Create a relative symbolic link if symlink path is given.