# HG changeset patch # User Henry S. Thompson # Date 1773245315 0 # Node ID 8c9e7578ed30e54292e07d3e71c19e463fcbb166 # Parent 279793350225fcab48be6692cfeca5437094b3fe refactor slightly, read whole warc file as test, seems to be working, still using zlib.decompressobj diff -r 279793350225 -r 8c9e7578ed30 lib/python/cc/warc.py --- a/lib/python/cc/warc.py Wed Mar 11 13:24:48 2026 +0000 +++ b/lib/python/cc/warc.py Wed Mar 11 16:08:35 2026 +0000 @@ -58,7 +58,6 @@ while not (done and bp >= bl): start_1: int = bp if not buf.startswith(b'WARC/1.0\r\n',bp): - breakpoint() raise ValueError("Not a WARC file? In %s at %s of %s (%s): %s[%s]"%(filename, bp,bl,fpos, (buf[bp:min(bl,bp+20)] if bp 0 and do.unused_data[eob] == 0: - eob += 1 - unused -= 1 - if unused > 0: - fp.seek(-unused, 2) - return decompressed + while bp < bl and data[bp] == 0: + bp += 1 + return (decompressed, bp) + +if __name__ == "__main__": + f=open(sys.argv[1],"rb") + buf = bytearray(BUFSIZE) + bufView = memoryview(buf) + bl: int = f.readinto(buf) + offset: int = 0 + bp: int = 0 + done: bool = bl < BUFSIZE + print(0, file=sys.stderr) + while True: + (unc, bp) = decompOneBlock(bufView, bl, bp) + if unc == b"": + break + print(offset + bp,unc[21:29],file=sys.stderr) + if (not done) and (keepLen := bl - bp) < BUFMIN: + # we need to shift and read more + print("shifting",file=sys.stderr) + offset += bp + buf[0:keepLen]=bufView[bp:bl] + with memoryview(buf)[keepLen:BUFSIZE] as xBuf: + nb=f.readinto(xBuf) + bl = keepLen+nb + done = bl < BUFSIZE + bp = 0 + fp.close() + f.close()