summaryrefslogtreecommitdiffstats
path: root/module/network
diff options
context:
space:
mode:
authorGravatar mkaay <mkaay@mkaay.de> 2010-12-19 16:07:04 +0100
committerGravatar mkaay <mkaay@mkaay.de> 2010-12-19 16:07:04 +0100
commitae021bd9938e726b0889d1b551946810c51934a3 (patch)
tree46b9bc9fe1dcfd24be2e4f21eeff1ac1fe45cf6d /module/network
parentlittle changes (diff)
downloadpyload-ae021bd9938e726b0889d1b551946810c51934a3.tar.xz
fixed chunk size calculation
Diffstat (limited to 'module/network')
-rw-r--r--module/network/HTTPChunk.py10
-rw-r--r--module/network/HTTPDownload.py6
2 files changed, 6 insertions, 10 deletions
diff --git a/module/network/HTTPChunk.py b/module/network/HTTPChunk.py
index 6ffc43078..6f9454c56 100644
--- a/module/network/HTTPChunk.py
+++ b/module/network/HTTPChunk.py
@@ -78,9 +78,7 @@ class HTTPChunk(HTTPBase):
break
count = self.bufferSize
if self.noRangeHeader:
- if self.range[1] <= self.arrived+count:
- count = min(count, self.arrived+count - self.range[1])
- running = False
+ count = min(count, self.range[1]-self.range[0] - self.arrived+count)
if self.bucket:
count = self.bucket.add(count)
if count == 0:
@@ -100,12 +98,10 @@ class HTTPChunk(HTTPBase):
self.speedCalcTime = inttime()
self.speedCalcLen = 0
size = len(data)
+ if self.arrived+size == self.range[1]-self.range[0]:
+ running = False
self.speedCalcLen += size
self.arrived += size
- if self.noRangeHeader:
- if self.range[1] <= self.arrived:
- self.fh.write(data[:-(self.arrived-self.range[1])])
- break
if data:
self.fh.write(data)
diff --git a/module/network/HTTPDownload.py b/module/network/HTTPDownload.py
index 98941ff08..4bba7724e 100644
--- a/module/network/HTTPDownload.py
+++ b/module/network/HTTPDownload.py
@@ -211,7 +211,7 @@ class HTTPDownload():
chunksize = size/chunks
lastchunk = chunksize
- chunk.range = (0, chunksize-1)
+ chunk.range = (0, chunksize)
chunk.noRangeHeader = True
self.size = chunk.size
self.info.setSize(self.size)
@@ -241,7 +241,6 @@ class HTTPDownload():
fh = open("%s.chunk%d" % (self.filename, i), "ab" if cont else "wb")
chunk = self._createChunk(fh, range=rng)
- self.chunks.append(chunk)
d = chunk.download()
if not chunk.resp.getcode() == 206 and i == 1: #no range supported, tell chunk0 to download everything
chunk.abort = True
@@ -251,6 +250,7 @@ class HTTPDownload():
self.info.clear()
self.info.addChunk("%s.chunk0" % (self.filename, ), (0, self.firstchunk.size), chunk.getEncoding())
break
+ self.chunks.append(chunk)
dg.addDeferred(d)
if not self.info.loaded:
@@ -284,7 +284,7 @@ if __name__ == "__main__":
print "starting"
dwnld = HTTPDownload(url, "test_100mb.bin")
- d = dwnld.download(chunks=1, resume=True)
+ d = dwnld.download(chunks=2, resume=True)
d.addCallback(callb)
d.addErrback(err)