def get_binary(self, url, dl_location,
mime='application/octet-stream', chunk_size=512,
timeout=3600):
"""
Actual download method with checksum checking.
Args:
url(str): URL of item to download
dl_location(str): storage path for downloaded artifact
Keyword Args:
mime: mimetype of content to retrieve
(default: 'application/octet-stream')
chunk_size: size of chunk to retrieve
timeout: download timeout
(default: 3600)
Returns:
MD5 hash of downloaded content
"""
get_bin_headers = {
'Accept': mime,
**self.headers
}
hash_md5 = hashlib.md5()
self.logger.debug('GET binary {}'.format(url))
with aiohttp.Timeout(timeout, loop=self.session.loop):
async with self.session.get(url, headers=get_bin_headers) as resp:
await self.check_http_status(resp)
with open(dl_location, 'wb') as fd:
while True:
with aiohttp.Timeout(60):
chunk = await resp.content.read(chunk_size)
if not chunk:
break
fd.write(chunk)
hash_md5.update(chunk)
return hash_md5.hexdigest()
评论列表
文章目录