MCPcopy
hub / github.com/legendary-gl/legendary / ChunkInfo

Class ChunkInfo

legendary/models/manifest.py:470–523  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

468
469
470class ChunkInfo:
471 def __init__(self, manifest_version=18):
472 self.guid = None
473 self.hash = 0
474 self.sha_hash = b''
475 self.window_size = 0
476 self.file_size = 0
477
478 self._manifest_version = manifest_version
479 # caches for things that are "expensive" to compute
480 self._group_num = None
481 self._guid_str = None
482 self._guid_num = None
483
484 def __repr__(self):
485 return '<ChunkInfo (guid={}, hash={}, sha_hash={}, group_num={}, window_size={}, file_size={})>'.format(
486 self.guid_str, self.hash, self.sha_hash.hex(), self.group_num, self.window_size, self.file_size
487 )
488
489 @property
490 def guid_str(self):
491 if not self._guid_str:
492 self._guid_str = '-'.join('{:08x}'.format(g) for g in self.guid)
493
494 return self._guid_str
495
496 @property
497 def guid_num(self):
498 if not self._guid_num:
499 self._guid_num = self.guid[3] + (self.guid[2] << 32) + (self.guid[1] << 64) + (self.guid[0] << 96)
500 return self._guid_num
501
502 @property
503 def group_num(self):
504 if self._guid_num is not None:
505 return self._group_num
506
507 self._group_num = (zlib.crc32(
508 struct.pack('<I', self.guid[0]) +
509 struct.pack('<I', self.guid[1]) +
510 struct.pack('<I', self.guid[2]) +
511 struct.pack('<I', self.guid[3])
512 ) & 0xffffffff) % 100
513 return self._group_num
514
515 @group_num.setter
516 def group_num(self, value):
517 self._group_num = value
518
519 @property
520 def path(self):
521 return '{}/{:02d}/{:016X}_{}.chunk'.format(
522 get_chunk_dir(self._manifest_version), self.group_num,
523 self.hash, ''.join('{:08X}'.format(g) for g in self.guid))
524
525
526class FML:

Callers 3

finalize_chunkMethod · 0.90
readMethod · 0.90
readMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected