# HG changeset patch # User Henry S. Thompson # Date 1766509172 0 # Node ID c05293f9d958b19d9ae09a856d2b10720ca743a2 # Parent cc70ae0b156d63517e963e273416f8c99124163a mostly working, date-stamp issue? diff -r cc70ae0b156d -r c05293f9d958 lib/python/cc/lmh/shrink.py --- a/lib/python/cc/lmh/shrink.py Mon Dec 22 22:23:37 2025 +0000 +++ b/lib/python/cc/lmh/shrink.py Tue Dec 23 16:59:32 2025 +0000 @@ -2,22 +2,23 @@ '''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 + Usage: shrink.py infile.cdb_in cdate_prefix outfile.cdb_in ''' import sys, io -fn = sys.argv.pop(1) -dp = sys.argv.pop(1) +ifn = sys.argv.pop(1) +dp = sys.argv.pop(1).encode('ascii') +ofn = sys.argv.pop(1) dpl = len(dp) saved = 0 -buf = io.BytesIO(bytearray(4)) +#buf = io.BytesIO(bytearray(4)) -with open(fn) as f: + +with open(ifn,'rb') as f, open(ofn,'wb') as of: for l in f: - sys.stdout.write(l) - sys.stdout.flush() - (bb,od,oe) = l.rstrip().split(':',2) - (os1,os2)=bb[1:].split(',') + of.write(l) + (bb,od,oe) = l.rstrip().split(b':',2) + (os1,os2)=bb[1:].split(b',') kl=int(os1) ll=int(os2) for i in range(dpl): @@ -27,13 +28,16 @@ nd = od[i-1:] else: nd = od - print(od,nd) + print(od,nd,file=sys.stderr) 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() + int.to_bytes(nli,4) + of.write(b'+%d,%d'%(kl-(len(od)-len(nd)),4)) + of.write(b':') + of.write(nd) + of.write(b':') + of.write(oe[:-ll]) + of.write(int.to_bytes(nli,4)) + of.write(b'\n') + +