CurseAPI.py 文件源码

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

项目:OpenMineMods 作者: OpenMineMods 项目源码 文件源码
def download_file(self, url: str, filepath: str, fname="", progf=False):
        """Download a file from `url` to `filepath/name`"""
        r = self.session.get(url, stream=True)
        dlen = r.headers.get("content-length")
        step = (100 / int(dlen))
        prog = 0
        if not fname:
            fname = unquote(Path(r.url).name)
        with open(filepath+"/"+fname, 'wb') as f:
            for chunk in r.iter_content(chunk_size=1024):
                if chunk:
                    prog += len(chunk)
                    if progf:
                        progf(int(step * prog))
                    f.write(chunk)
        if progf:
            progf(0)
        return filepath+"/"+fname
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号