Rev3225, Handle correctly and test out of range bigfile requests
This commit is contained in:
parent
9c4093dc7c
commit
3fb9f900f6
3 changed files with 12 additions and 2 deletions
|
@ -426,7 +426,7 @@ class BigFile(object):
|
||||||
|
|
||||||
def read(self, buff=64 * 1024):
|
def read(self, buff=64 * 1024):
|
||||||
pos = self.f.tell()
|
pos = self.f.tell()
|
||||||
read_until = pos + buff
|
read_until = min(self.size, pos + buff)
|
||||||
requests = []
|
requests = []
|
||||||
# Request all required blocks
|
# Request all required blocks
|
||||||
while 1:
|
while 1:
|
||||||
|
|
|
@ -209,6 +209,16 @@ class TestBigfile:
|
||||||
|
|
||||||
assert len(requests) == 2 # Two block download
|
assert len(requests) == 2 # Two block download
|
||||||
|
|
||||||
|
# Test out of range request
|
||||||
|
f.seek(5 * 1024 * 1024)
|
||||||
|
data = f.read(1024 * 1024 * 30)
|
||||||
|
assert len(data) == 10 * 1000 * 1000 - (5 * 1024 * 1024)
|
||||||
|
|
||||||
|
f.seek(30 * 1024 * 1024)
|
||||||
|
data = f.read(1024 * 1024 * 30)
|
||||||
|
assert len(data) == 0
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("piecefield_obj", [BigfilePiecefield, BigfilePiecefieldPacked])
|
@pytest.mark.parametrize("piecefield_obj", [BigfilePiecefield, BigfilePiecefieldPacked])
|
||||||
def testPiecefield(self, piecefield_obj, site):
|
def testPiecefield(self, piecefield_obj, site):
|
||||||
|
|
|
@ -10,7 +10,7 @@ class Config(object):
|
||||||
|
|
||||||
def __init__(self, argv):
|
def __init__(self, argv):
|
||||||
self.version = "0.6.1"
|
self.version = "0.6.1"
|
||||||
self.rev = 3224
|
self.rev = 3225
|
||||||
self.argv = argv
|
self.argv = argv
|
||||||
self.action = None
|
self.action = None
|
||||||
self.config_file = "zeronet.conf"
|
self.config_file = "zeronet.conf"
|
||||||
|
|
Loading…
Reference in a new issue