Skip to content

Commit 243bc8b

Browse files
committed
Merge pull request #93 from dtynn/wanglin/hotfix/rio_4m
rio 4m bug fixed
2 parents 5b07686 + f16ce37 commit 243bc8b

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

qiniu/resumable_io.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
_chunk_size = 256 * 1024
1515
_try_times = 3
1616
_block_size = 4 * 1024 * 1024
17+
_block_mask = _block_size - 1
1718

1819
class Error(Exception):
1920
value = None
@@ -141,7 +142,7 @@ def resumable_block_put(block, index, extra, uptoken):
141142

142143
def block_count(size):
143144
global _block_size
144-
return size / _block_size + 1
145+
return (size + _block_mask) / _block_size
145146

146147
def mkblock(client, block_size, first_chunk):
147148
url = "http://%s/mkblk/%s" % (conf.UP_HOST, block_size)

qiniu/test/resumable_io_test.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,31 @@ def test_put(self):
7777
self.assertEqual(ret["hash"], "FnyTMUqPNRTdk1Wou7oLqDHkBm_p", "hash not match")
7878
rs.Client().delete(bucket, key)
7979

80+
def test_put_4m(self):
81+
ostype = platform.system()
82+
if ostype.lower().find("windows") != -1:
83+
tmpf = "".join([os.getcwd(), os.tmpnam()])
84+
else:
85+
tmpf = os.tmpnam()
86+
dst = open(tmpf, 'wb')
87+
dst.write("abcd" * 1024 * 1024)
88+
dst.flush()
89+
90+
policy = rs.PutPolicy(bucket)
91+
extra = resumable_io.PutExtra(bucket)
92+
extra.bucket = bucket
93+
extra.params = {"x:foo": "test"}
94+
key = "sdk_py_resumable_block_6_%s" % r(9)
95+
localfile = dst.name
96+
ret, err = resumable_io.put_file(policy.token(), key, localfile, extra)
97+
assert ret.get("x:foo") == "test", "return data not contains 'x:foo'"
98+
dst.close()
99+
os.remove(tmpf)
100+
101+
assert err is None, err
102+
self.assertEqual(ret["hash"], "FnIVmMd_oaUV3MLDM6F9in4RMz2U", "hash not match")
103+
rs.Client().delete(bucket, key)
104+
80105

81106
if __name__ == "__main__":
82107
unittest.main()

0 commit comments

Comments
 (0)