# HG changeset patch # User Henry S. Thompson # Date 1688754623 -3600 # Node ID 9c63039a9b6d333636ea73ec37236f7a58575f35 # Parent 0dc144bd027cc4f47bf9d72e9caeeab25e3e43f0 little steps diff -r 0dc144bd027c -r 9c63039a9b6d bin/warc.py --- a/bin/warc.py Fri Jul 07 19:04:16 2023 +0100 +++ b/bin/warc.py Fri Jul 07 19:30:23 2023 +0100 @@ -16,8 +16,8 @@ bufSize=2*1024*1024 hdrMax=16*1024 buf=bytearray(bufSize) - hdrBuf=memoryview(buf)[:hdrMax] - fpos=bl=stream.readinto(hdrBuf) + with memoryview(buf)[:hdrMax] as hdrBuf: + fpos=bl=stream.readinto(hdrBuf) while True: bp=0 while buf.startswith(b'\r\n',bp): @@ -47,22 +47,24 @@ if whole: pass # buf[bp:(bp:=bp+ln)]=l elif (parts & 1): - print('cb') OUT=callback(wtype,buf[bob:eol],1) if parts!=1: # everything from bv= goes here # need to read more if eol+length>hdrMax pass - print(wtype,bob,eol,length) + print(wtype,bob,bp,eol,length,file=sys.stderr) jumpTo=bp+length - buf[0:hdrMax-jumpTo]=buf[jumpTo:hdrMax] - stream.seek(fpos:=fpos+jumpTo) + buf[0:jumpTo]=buf[jumpTo:hdrMax] + _fpos=stream.seek(fpos:=fpos+jumpTo) + print('fp',_fpos,fpos,file=sys.stderr) if done: - continue - n=stream.readinto(memoryview(buf)[hdrMax-jumpTo:hdrMax]) - print('read',n) + print('finished',file=sys.stderr) + break + with memoryview(buf) as mv: + n=stream.readinto(mv[hdrMax-jumpTo:hdrMax]) + print('read',n,file=sys.stderr) if n