import lzma import io import os from _compression import DecompressReader DIR = r'D:\more_bad_lzma_files' for filename in os.listdir(DIR): file_path = os.path.join(DIR, filename) if not os.path.isfile(file_path): continue # read compressed file with open(file_path, 'rb') as f: compressed = f.read() print(file_path, flush=True) # decompress with specified max_length full_size = None for max_length in range(-1, 1000): if max_length == 0: continue fp = io.BytesIO(compressed) dr = DecompressReader(fp, lzma.LZMADecompressor) ret = [] while 1: try: out = dr.read(max_length) except: break if not out: break ret.append(out) result = b''.join(ret) if not dr._eof: print(f'{filename} incomplete when max_length == {max_length}, decompressed size: {len(result)}', flush=True) dr.close() fp.close() continue dr.close() fp.close() full_size = len(result) if max_length > full_size: break if not full_size is None: print(f'full size should be: {full_size}\n', flush=True) print('ok')