Skip to content

Commit c6b8609

Browse files
committed
rio 4m bug fixed
1 parent 5b07686 commit c6b8609

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-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: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,32 @@ 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+
src = urllib.urlopen("http://for-temp.qiniudn.com/FnIVmMd_oaUV3MLDM6F9in4RMz2U")
82+
ostype = platform.system()
83+
if ostype.lower().find("windows") != -1:
84+
tmpf = "".join([os.getcwd(), os.tmpnam()])
85+
else:
86+
tmpf = os.tmpnam()
87+
dst = open(tmpf, 'wb')
88+
shutil.copyfileobj(src, dst)
89+
src.close()
90+
91+
policy = rs.PutPolicy(bucket)
92+
extra = resumable_io.PutExtra(bucket)
93+
extra.bucket = bucket
94+
extra.params = {"x:foo": "test"}
95+
key = "sdk_py_resumable_block_4m_%s" % r(9)
96+
localfile = dst.name
97+
ret, err = resumable_io.put_file(policy.token(), key, localfile, extra)
98+
assert ret.get("x:foo") == "test", "return data not contains 'x:foo'"
99+
dst.close()
100+
os.remove(tmpf)
101+
102+
assert err is None, err
103+
self.assertEqual(ret["hash"], "FnIVmMd_oaUV3MLDM6F9in4RMz2U", "hash not match")
104+
rs.Client().delete(bucket, key)
105+
80106

81107
if __name__ == "__main__":
82108
unittest.main()

0 commit comments

Comments
 (0)