diff options
author | mkaay <mkaay@mkaay.de> | 2010-12-19 16:07:04 +0100 |
---|---|---|
committer | mkaay <mkaay@mkaay.de> | 2010-12-19 16:07:04 +0100 |
commit | ae021bd9938e726b0889d1b551946810c51934a3 (patch) | |
tree | 46b9bc9fe1dcfd24be2e4f21eeff1ac1fe45cf6d /module/network | |
parent | little changes (diff) | |
download | pyload-ae021bd9938e726b0889d1b551946810c51934a3.tar.xz |
fixed chunk size calculation
Diffstat (limited to 'module/network')
-rw-r--r-- | module/network/HTTPChunk.py | 10 | ||||
-rw-r--r-- | module/network/HTTPDownload.py | 6 |
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) |