| 90 | return (self.arrived * 100) / self.size |
| 91 | |
| 92 | def _copyChunks(self): |
| 93 | init = fs_encode(self.info.getChunkName(0)) # initial chunk name |
| 94 | |
| 95 | if self.info.getCount() > 1: |
| 96 | fo = open(init, "rb+") # first chunkfile |
| 97 | for i in range(1, self.info.getCount()): |
| 98 | # input file |
| 99 | fo.seek(self.info.getChunkRange(i - 1)[1] + 1) # seek to beginning of chunk, to get rid of overlapping chunks |
| 100 | fname = fs_encode("%s.chunk%d" % (self.filename, i)) |
| 101 | fi = open(fname, "rb") |
| 102 | buf = 32 * 1024 |
| 103 | while True: # copy in chunks, consumes less memory |
| 104 | data = fi.read(buf) |
| 105 | if not data: |
| 106 | break |
| 107 | fo.write(data) |
| 108 | fi.close() |
| 109 | if fo.tell() < self.info.getChunkRange(i)[1]: |
| 110 | fo.close() |
| 111 | remove(init) |
| 112 | self.info.remove() # there are probably invalid chunks |
| 113 | raise Exception("Downloaded content was smaller than expected. Try to reduce download connections.") |
| 114 | remove(fname) # remove chunk |
| 115 | fo.close() |
| 116 | |
| 117 | if self.nameDisposition and self.disposition: |
| 118 | self.filename = save_join(dirname(self.filename), self.nameDisposition) |
| 119 | |
| 120 | move(init, fs_encode(self.filename)) |
| 121 | self.info.remove() # remove info file |
| 122 | |
| 123 | def download(self, chunks=1, resume=False): |
| 124 | """ returns new filename or None """ |