diff --git a/rsrcfork/compress/__init__.py b/rsrcfork/compress/__init__.py index 292854b..8c56a17 100644 --- a/rsrcfork/compress/__init__.py +++ b/rsrcfork/compress/__init__.py @@ -18,7 +18,7 @@ def _decompress_application(data: bytes, header_info: CompressedApplicationHeade else: raise DecompressError(f"Unsupported 'dcmp' ID: {header_info.dcmp_id}, expected 0 or 1") - return decompress_func(data, header_info.decompressed_length, debug=debug) + return decompress_func(header_info, data, debug=debug) def _decompress_system(data: bytes, header_info: CompressedSystemHeaderInfo, *, debug: bool=False) -> bytes: @@ -27,7 +27,7 @@ def _decompress_system(data: bytes, header_info: CompressedSystemHeaderInfo, *, else: raise DecompressError(f"Unsupported 'dcmp' ID: {header_info.dcmp_id}, expected 2") - return decompress_func(data, header_info.decompressed_length, header_info.parameters, debug=debug) + return decompress_func(header_info, data, debug=debug) def decompress(data: bytes, *, debug: bool=False) -> bytes: diff --git a/rsrcfork/compress/dcmp0.py b/rsrcfork/compress/dcmp0.py index 864c7e9..eebdd8d 100644 --- a/rsrcfork/compress/dcmp0.py +++ b/rsrcfork/compress/dcmp0.py @@ -36,7 +36,7 @@ TABLE = [TABLE_DATA[i:i + 2] for i in range(0, len(TABLE_DATA), 2)] assert len(TABLE) == len(range(0x4b, 0xfe)) -def decompress(data: bytes, decompressed_length: int, *, debug: bool=False) -> bytes: +def decompress(header_info: common.CompressedApplicationHeaderInfo, data: bytes, *, debug: bool=False) -> bytes: """Decompress compressed data in the format used by 'dcmp' (0).""" prev_literals = [] @@ -287,7 +287,7 @@ def decompress(data: bytes, decompressed_length: int, *, debug: bool=False) -> b else: raise common.DecompressError(f"Unknown tag byte: 0x{data[i]:>02x}") - if decompressed_length % 2 != 0 and len(decompressed) == decompressed_length + 1: + if header_info.decompressed_length % 2 != 0 and len(decompressed) == header_info.decompressed_length + 1: # Special case: if the decompressed data length stored in the header is odd and one less than the length of the actual decompressed data, drop the last byte. # This is necessary because nearly all codes generate data in groups of 2 or 4 bytes, so it is basically impossible to represent data with an odd length using this compression format. decompressed = decompressed[:-1] diff --git a/rsrcfork/compress/dcmp1.py b/rsrcfork/compress/dcmp1.py index 7f9da58..b1580b0 100644 --- a/rsrcfork/compress/dcmp1.py +++ b/rsrcfork/compress/dcmp1.py @@ -19,7 +19,7 @@ TABLE = [TABLE_DATA[i:i + 2] for i in range(0, len(TABLE_DATA), 2)] assert len(TABLE) == len(range(0xd5, 0xfe)) -def decompress(data: bytes, decompressed_length: int, *, debug: bool=False) -> bytes: +def decompress(header_info: common.CompressedApplicationHeaderInfo, data: bytes, *, debug: bool=False) -> bytes: """Decompress compressed data in the format used by 'dcmp' (1).""" prev_literals = [] diff --git a/rsrcfork/compress/dcmp2.py b/rsrcfork/compress/dcmp2.py index b7e320c..103baa3 100644 --- a/rsrcfork/compress/dcmp2.py +++ b/rsrcfork/compress/dcmp2.py @@ -131,10 +131,10 @@ def _decompress_system_tagged(data: bytes, decompressed_length: int, table: typi return b"".join(parts) -def decompress(data: bytes, decompressed_length: int, parameters: bytes, *, debug: bool=False) -> bytes: +def decompress(header_info: common.CompressedSystemHeaderInfo, data: bytes, *, debug: bool=False) -> bytes: """Decompress compressed data in the format used by 'dcmp' (2).""" - unknown, table_count_m1, flags_raw = STRUCT_PARAMETERS.unpack(parameters) + unknown, table_count_m1, flags_raw = STRUCT_PARAMETERS.unpack(header_info.parameters) if debug: print(f"Value of unknown parameter field: 0x{unknown:>04x}") @@ -172,4 +172,4 @@ def decompress(data: bytes, decompressed_length: int, parameters: bytes, *, debu else: decompress_func = _decompress_system_untagged - return decompress_func(data[data_start:], decompressed_length, table, debug=debug) + return decompress_func(data[data_start:], header_info.decompressed_length, table, debug=debug)