Mercurial > hg > cc > cirrus_work
comparison lib/python/unpackz.py @ 240:51bd09d4289e
eof pblms fixed, seems to work
author | Henry S. Thompson <ht@inf.ed.ac.uk> |
---|---|
date | Tue, 01 Oct 2024 15:59:26 +0100 |
parents | 992f59d21832 |
children | 96021cfee209 |
comparison
equal
deleted
inserted
replaced
239:992f59d21832 | 240:51bd09d4289e |
---|---|
16 exit(1) | 16 exit(1) |
17 with open(sys.argv[1],'rb') as f: | 17 with open(sys.argv[1],'rb') as f: |
18 z = isal.isal_zlib.decompressobj(31) | 18 z = isal.isal_zlib.decompressobj(31) |
19 count = 0 | 19 count = 0 |
20 while True: | 20 while True: |
21 if z.unused_data == b"": | 21 if z.unused_data == b"": |
22 #print('n', obuf_len, file=sys.stderr) | 22 #print('n', obuf_len, file=sys.stderr) |
23 if lastbuf: # buf == b"": | |
24 if outfile is None: | |
25 print(obuf_len, offset) | |
26 else: | |
27 outfile.write(b'\000%d\000%d\000'%(obuf_len, offset)) | |
28 if count!=0: | |
29 print("Unused data: count=%s offset=%s ?"%(count, offset), | |
30 file=sys.stderr) | |
31 break | |
23 if nbuf: | 32 if nbuf: |
24 obuf_len += BUFSIZE # still no EOS after a full buffer processed | 33 obuf_len += BUFSIZE # still no EOS after a full buffer processed |
25 buf = f.read(BUFSIZE) | 34 buf = f.read(BUFSIZE) |
26 nbuf = True | 35 nbuf = True |
27 lastbuf = ((truesize:=len(buf)) < BUFSIZE) # will only succeed if now at EOF | 36 lastbuf = ((truesize:=len(buf)) < BUFSIZE) # will only succeed if now at EOF |
28 if buf == b"": | |
29 if outfile is None: | |
30 print(count, offset) | |
31 else: | |
32 outfile.write(b'\000%d\000%d\000'%(count, offset)) | |
33 break | |
34 else: | 37 else: |
35 buf_len = len(buf) | 38 buf_len = len(buf) |
36 #print('b', obuf_len, buf_len, len(z.unused_data), len(buf)-len(z.unused_data), | 39 #print('b', obuf_len, buf_len, len(z.unused_data), len(buf)-len(z.unused_data), |
37 # nbuf, lastbuf, file=sys.stderr) | 40 # nbuf, lastbuf, file=sys.stderr) |
38 count = (obuf_len if (buf_len == truesize) else 0) + \ | 41 count = (obuf_len if (buf_len == truesize) else 0) + \ |
39 (len(buf)-len(z.unused_data)) | 42 (len(buf)-len(z.unused_data)) |
40 if outfile is None: | 43 if outfile is None: |
41 print(count, offset) | 44 print(count, offset) |
42 else: | 45 else: |
43 outfile.write(b'\000%d\000%d\000'%(count, offset)) | 46 outfile.write(b'\000%d\000%d\000'%(count, offset)) |
47 # if (offset == 1352249): | |
48 # breakpoint() | |
44 offset += count | 49 offset += count |
45 count = 0 | 50 count = 0 |
46 buf = z.unused_data | 51 buf = z.unused_data |
47 obuf_len = len(buf) | 52 obuf_len = len(buf) |
48 nbuf = False | 53 nbuf = False |
49 z = isal.isal_zlib.decompressobj(31) | 54 z = isal.isal_zlib.decompressobj(31) |
50 got = z.decompress(buf) | 55 got = z.decompress(buf) |
51 if outfile is not None: | 56 if outfile is not None: |
52 outfile.write(got) | 57 outfile.write(got) |
53 if count!=0: | |
54 print("Unused data: count=%s offset=%s ?"%(count, offset), | |
55 file=sys.stderr) | |
56 if outfile is not None: | 58 if outfile is not None: |
57 outfile.close() | 59 outfile.close() |