client.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:rauc-hawkbit 作者: rauc 项目源码 文件源码
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()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号