Mercurial > hg > cc > cirrus_work
comparison lib/python/unpackz.py @ 242:e117424e244a
cleaned up indentation to 2 spaces throughout
author | Henry S. Thompson <ht@inf.ed.ac.uk> |
---|---|
date | Wed, 02 Oct 2024 11:09:58 +0100 |
parents | 96021cfee209 |
children |
comparison
equal
deleted
inserted
replaced
241:96021cfee209 | 242:e117424e244a |
---|---|
26 | 26 |
27 with open(sys.argv[1],'rb') as f: | 27 with open(sys.argv[1],'rb') as f: |
28 z = isal.isal_zlib.decompressobj(31) | 28 z = isal.isal_zlib.decompressobj(31) |
29 count = 0 | 29 count = 0 |
30 while True: | 30 while True: |
31 if z.unused_data == b"": | 31 if z.unused_data == b"": |
32 #print('n', obuf_len, file=sys.stderr) | 32 #print('n', obuf_len, file=sys.stderr) |
33 if lastbuf: # buf == b"": | 33 if lastbuf: # buf == b"": |
34 if outfile is None: | 34 if outfile is None: |
35 print(obuf_len, offset) | 35 print(obuf_len, offset) |
36 else: | 36 else: |
37 outfile.write(b'\000%d\000%d\000'%(obuf_len, offset)) | 37 outfile.write(b'\000%d\000%d\000'%(obuf_len, offset)) |
38 if count!=0: | 38 if count!=0: |
39 print("Unused data: count=%s offset=%s ?"%(count, offset), | 39 print("Unused data: count=%s offset=%s ?"%(count, offset), |
40 file=sys.stderr) | 40 file=sys.stderr) |
41 break | 41 break |
42 if nbuf: | 42 if nbuf: |
43 obuf_len += BUFSIZE # still no EOS after a full buffer processed | 43 obuf_len += BUFSIZE # still no EOS after a full buffer processed |
44 buf = f.read(BUFSIZE) | 44 buf = f.read(BUFSIZE) |
45 nbuf = True | 45 nbuf = True |
46 lastbuf = ((truesize:=len(buf)) < BUFSIZE) # will only succeed if now at EOF | 46 lastbuf = ((truesize:=len(buf)) < BUFSIZE) # will only succeed if now at EOF |
47 else: | |
48 buf_len = len(buf) | |
49 #print('b', obuf_len, buf_len, len(z.unused_data), len(buf)-len(z.unused_data), | |
50 # nbuf, lastbuf, file=sys.stderr) | |
51 count = (obuf_len if (buf_len == truesize) else 0) + \ | |
52 (len(buf)-len(z.unused_data)) | |
53 if outfile is None: | |
54 print(count, offset) | |
47 else: | 55 else: |
48 buf_len = len(buf) | 56 outfile.write(b'\000%d\000%d\000'%(count, offset)) |
49 #print('b', obuf_len, buf_len, len(z.unused_data), len(buf)-len(z.unused_data), | 57 #if (offset == 1352249): |
50 # nbuf, lastbuf, file=sys.stderr) | 58 # breakpoint() |
51 count = (obuf_len if (buf_len == truesize) else 0) + \ | 59 offset += count |
52 (len(buf)-len(z.unused_data)) | 60 count = 0 |
53 if outfile is None: | 61 buf = z.unused_data |
54 print(count, offset) | 62 obuf_len = len(buf) |
55 else: | 63 nbuf = False |
56 outfile.write(b'\000%d\000%d\000'%(count, offset)) | 64 z = isal.isal_zlib.decompressobj(31) |
57 # if (offset == 1352249): | 65 got = z.decompress(buf) |
58 # breakpoint() | 66 if outfile is not None: |
59 offset += count | 67 outfile.write(got) |
60 count = 0 | |
61 buf = z.unused_data | |
62 obuf_len = len(buf) | |
63 nbuf = False | |
64 z = isal.isal_zlib.decompressobj(31) | |
65 got = z.decompress(buf) | |
66 if outfile is not None: | |
67 outfile.write(got) | |
68 if outfile is not None: | 68 if outfile is not None: |
69 outfile.close() | 69 outfile.close() |