# HG changeset patch # User Henry S. Thompson # Date 1766441896 0 # Node ID b6203074f18c82e1adbceaa8a0bc4927a6f2cd87 # Parent d52602a64e09de9abf836d9becb6d0b504ba3891 to fix unshrunk 2023-40, not yet working diff -r d52602a64e09 -r b6203074f18c lib/python/cc/lmh/shrink.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/python/cc/lmh/shrink.py Mon Dec 22 22:18:16 2025 +0000 @@ -0,0 +1,39 @@ +#!/usr/bin/env python3 +'''Shrink cdb_input-style files after the fact + Each record is encoded as +klen,dlen:key->data + + Usage: shrink.py file.cdb_in cdate_prefix | sponge file.cdb_in +''' +import sys, io + +fn = sys.argv.pop(1) +dp = sys.argv.pop(1) +dpl = len(dp) +saved = 0 +buf = io.BytesIO(bytearray(4)) + +with open(fn) as f: + for l in f: + sys.stdout.write(l) + sys.stdout.flush() + (bb,od,oe) = l.rstrip().split(':',2) + (os1,os2)=bb[1:].split(',') + kl=int(os1) + ll=int(os2) + for i in range(dpl): + if od[i] != dp[i]: + break + if i > 0: + nd = od[i-1:] + else: + nd = od + print(od,nd) + ol = oe[-ll:] + nli = int(ol) + nl = int.to_bytes(nli,4) + print("+%s,%s"%(kl-(len(od)-len(nd)),4),nd,oe[:-ll],sep=':',end='') + buf.seek(0) + buf.write(nl) + sys.stdout.buffer.write(buf.getbuffer()) + sys.stdout.buffer.write(b'\n') + exit()