Skip to content

Commit

Permalink
fix(download): 修复下载方法中在下载文件 HTTP 请求未返回 Content-Length 头部导致下载方法失败的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
leafcoder committed Jul 22, 2024
1 parent d830a79 commit c24561b
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 16 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## [0.6.2](https://github.com/teambge/bge-python-sdk/compare/v0.6.1...v0.6.2) (2024-07-22)


### Bug Fixes

* **download:** 修复下载方法中在下载文件 HTTP 请求未返回 Content-Length 头部导致下载方法失败的问题 ([5a33e8b](https://github.com/teambge/bge-python-sdk/commit/5a33e8bfa7174510eeb2ab1951bebc3220e067a3))



## [0.6.1](https://github.com/teambge/bge-python-sdk/compare/v0.6.0...v0.6.1) (2023-12-04)


Expand Down
36 changes: 24 additions & 12 deletions bgesdk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -890,18 +890,30 @@ def download(self, object_name, fp, region=None,
timeout = self.timeout
try:
with requests.get(url, stream=True, timeout=timeout) as r:
total = int(r.headers['content-length'])
for chunk in r.iter_content(chunk_size):
size += len(chunk)
eq_size = int(size * prog_size / total)
equal_s = '=' * eq_size
blank_s = ' ' * (prog_size - eq_size)
progress = '>'.join((equal_s, blank_s))
percent = '%.2f%%' % float(size / total * 100)
sys.stdout.write(
'\r\t%s [%s]' % (percent.rjust(7), progress)
)
fp.write(chunk)
total = r.headers.get('content-length')
if total is not None:
total = int(total)
for chunk in r.iter_content(chunk_size):
size += len(chunk)
eq_size = int(size * prog_size / total)
equal_s = '=' * eq_size
blank_s = ' ' * (prog_size - eq_size)
progress = '>'.join((equal_s, blank_s))
percent = '%.2f%%' % float(size / total * 100)
sys.stdout.write(
'\r\t%s [%s]' % (percent.rjust(7), progress)
)
sys.stdout.flush()
fp.write(chunk)
else:
for chunk in r.iter_content(chunk_size):
size += len(chunk)
sys.stdout.write(
'\r\t已下载文件:%s' % human_byte(size).ljust(7)
)
sys.stdout.flush()
fp.write(chunk)
sys.stdout.write('\n')
flush_func = getattr(fp, 'flush', None)
if flush_func:
flush_func()
Expand Down
2 changes: 1 addition & 1 deletion bgesdk/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#-*- coding: utf-8 -*-

__version__ = '0.6.1'
__version__ = '0.6.2'
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bge-python-sdk",
"version": "0.6.1",
"version": "0.6.2",
"scripts": {
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s",
"init_changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0"
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = bge-python-sdk
version = 0.6.1
version = 0.6.2
description = 可用于调用 BGE 开放平台的相关接口。
long_description = file: README.md
long_description_content_type = text/markdown
Expand Down
2 changes: 1 addition & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
sonar.projectName=bge-python-sdk
sonar.projectVersion=0.6.1
sonar.projectVersion=0.6.2
sonar.host.url=https://sonarqube.omgut.com
sonar.projectKey=bge_bge-python-sdk_AX6jmT2y6I6LwTlVf_Z1
sonar.links.homepage=https://github.com/teambge/bge-python-sdk
Expand Down

0 comments on commit c24561b

Please sign in to comment.