Skip to content

Commit

Permalink
长度大于256才进行gzip压缩
Browse files Browse the repository at this point in the history
  • Loading branch information
codeif committed Mar 24, 2022
1 parent 40eff10 commit d0642e2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[flake8]
max-line-length = 88
9 changes: 5 additions & 4 deletions qcos/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@ def smart_put_object(self, key, data, content_type=None, headers={}, **kwargs):
data = json.dumps(data, ensure_ascii=False)
if isinstance(data, str):
data = data.encode("utf-8")
gzip_data = gzip.compress(data)
if len(data) > len(gzip_data):
headers["Content-Encoding"] = "gzip"
data = gzip_data
if len(data) > 256:
gzip_data = gzip.compress(data)
if len(data) > len(gzip_data):
headers["Content-Encoding"] = "gzip"
data = gzip_data
return self.put_object(key, data, content_type, headers=headers, **kwargs)

def get_object_or_none(self, key):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

setup(
name="qcos",
version="2.2.2",
version="2.2.3",
description="腾讯云对象存储库,支持命令行",
long_description=readme,
author="codeif",
Expand Down

0 comments on commit d0642e2

Please sign in to comment.