8 byte magic and store docs

This commit is contained in:
Richard
2024-01-04 22:11:23 +01:00
parent 1b7a528655
commit 524ba45639
3 changed files with 22 additions and 9 deletions

View File

@@ -23,7 +23,7 @@ class Commander(CommandLine):
self.hist_file = hist_file
if os.path.isfile(hist_file):
readline.read_history_file(hist_file)
self.store = Store(store_file, True)
self.store = Store(store_file, False)
self.agent = self.select_agent()
self.api = Api(self.store, self.agent)
self.centcom = CentralCommand(self.store, self.api)

View File

@@ -24,7 +24,7 @@ class StoreUnpickler(pickle.Unpickler):
return self.store
raise pickle.UnpicklingError("I don know the persid!")
CHUNK_MAGIC = b'ChNk'
CHUNK_MAGIC = b'ChNkcHnK'
class ChunkHeader:
def __init__(self):
@@ -37,12 +37,12 @@ class ChunkHeader:
@classmethod
def parse(cls, fil):
offset = fil.tell()
d = fil.read(20)
if len(d) < 20:
d = fil.read(24)
if len(d) < 24:
return None
o = cls()
o.offset = offset
o.magic, d, o.used = unpack('<4sQQ', d)
o.magic, d, o.used = unpack('<8sQQ', d)
o.size = d & 0x7fffffffffffffff
o.in_use = d & 0x8000000000000000 != 0
if o.magic != CHUNK_MAGIC:
@@ -54,7 +54,7 @@ class ChunkHeader:
d = self.size
if self.in_use:
d |= 1 << 63
d = pack('<4sQQ', self.magic, d, self.used)
d = pack('<8sQQ', self.magic, d, self.used)
f.write(d)
def __repr__(self):
@@ -117,13 +117,13 @@ class Store:
self.p(hdr)
total += hdr.size
if not hdr.in_use:
print(f"skip {hdr.size} {self.fil.tell()}")
# print(f"skip {hdr.size} {self.fil.tell()}")
self.fil.seek(hdr.size, 1)
free += hdr.size
else:
data = self.fil.read(hdr.used)
self.load_object(data, offset)
print(f"pad {hdr.size - hdr.used}")
# print(f"pad {hdr.size - hdr.used}")
self.fil.seek(hdr.size - hdr.used, 1)
cnt += 1
offset = self.fil.tell()