| 198 | self.writeBlock(extent.inhdr, extent.blkhdr, rawblock) |
| 199 | |
| 200 | def run(self): |
| 201 | while self.blkCountOut < len(self.blkindex): |
| 202 | if not self.inF: |
| 203 | fname = self.inFileName(self.inFn) |
| 204 | print("Input file " + fname) |
| 205 | try: |
| 206 | self.inF = open(fname, "rb") |
| 207 | except IOError: |
| 208 | print("Premature end of block data") |
| 209 | return |
| 210 | |
| 211 | inhdr = self.read_xored(self.inF, 8) |
| 212 | if (not inhdr or (inhdr[0] == "\0")): |
| 213 | self.inF.close() |
| 214 | self.inF = None |
| 215 | self.inFn = self.inFn + 1 |
| 216 | continue |
| 217 | |
| 218 | inMagic = inhdr[:4] |
| 219 | if (inMagic != self.settings['netmagic']): |
| 220 | # Seek backwards 7 bytes (skipping the first byte in the previous search) |
| 221 | # and continue searching from the new position if the magic bytes are not |
| 222 | # found. |
| 223 | self.inF.seek(-7, os.SEEK_CUR) |
| 224 | continue |
| 225 | inLenLE = inhdr[4:] |
| 226 | su = struct.unpack("<I", inLenLE) |
| 227 | inLen = su[0] - 80 # length without header |
| 228 | blk_hdr = self.read_xored(self.inF, 80) |
| 229 | inExtent = BlockExtent(self.inFn, self.inF.tell(), inhdr, blk_hdr, inLen) |
| 230 | |
| 231 | self.hash_str = calc_hash_str(blk_hdr) |
| 232 | if self.hash_str not in blkmap: |
| 233 | # Because blocks can be written to files out-of-order as of 0.10, the script |
| 234 | # may encounter blocks it doesn't know about. Treat as debug output. |
| 235 | if settings['debug_output'] == 'true': |
| 236 | print("Skipping unknown block " + self.hash_str) |
| 237 | self.inF.seek(inLen, os.SEEK_CUR) |
| 238 | continue |
| 239 | |
| 240 | blkHeight = self.blkmap[self.hash_str] |
| 241 | self.blkCountIn += 1 |
| 242 | |
| 243 | if self.blkCountOut == blkHeight: |
| 244 | # If in-order block, just copy |
| 245 | rawblock = self.read_xored(self.inF, inLen) |
| 246 | self.writeBlock(inhdr, blk_hdr, rawblock) |
| 247 | |
| 248 | # See if we can catch up to prior out-of-order blocks |
| 249 | while self.blkCountOut in self.blockExtents: |
| 250 | self.copyOneBlock() |
| 251 | |
| 252 | else: # If out-of-order, skip over block data for now |
| 253 | self.blockExtents[blkHeight] = inExtent |
| 254 | if self.outOfOrderSize < self.settings['out_of_order_cache_sz']: |
| 255 | # If there is space in the cache, read the data |
| 256 | # Reading the data in file sequence instead of seeking and fetching it later is preferred, |
| 257 | # but we don't want to fill up memory |