diff --git a/rsrcfork/__main__.py b/rsrcfork/__main__.py index b93b91f..0af37b4 100644 --- a/rsrcfork/__main__.py +++ b/rsrcfork/__main__.py @@ -197,13 +197,13 @@ def _describe_resource(res: api.Resource, *, include_type: bool, decompress: boo if decompress and api.ResourceAttrs.resCompressed in res.attributes: try: - res.data + res.compressed_info except compress.DecompressError: - length_desc = f"decompression failed ({len(res.data_raw)} bytes compressed)" + length_desc = f"decompression failed ({res.length_raw} bytes compressed)" else: - length_desc = f"{len(res.data)} bytes ({len(res.data_raw)} bytes compressed)" + length_desc = f"{res.length} bytes ({res.length_raw} bytes compressed)" else: - length_desc = f"{len(res.data_raw)} bytes" + length_desc = f"{res.length_raw} bytes" content_desc_parts.append(length_desc) attrs = _decompose_flags(res.attributes) diff --git a/rsrcfork/api.py b/rsrcfork/api.py index 9ea6abe..b1819f3 100644 --- a/rsrcfork/api.py +++ b/rsrcfork/api.py @@ -154,6 +154,27 @@ class Resource(object): else: return None + @property + def length_raw(self) -> int: + """The length of the raw resource data, which may be compressed. + + Accessing this attribute may be faster than computing len(self.data_raw) manually. + """ + + return len(self.data_raw) + + @property + def length(self) -> int: + """The length of the resource data. If the resource data is compressed, this is the length of the data after decompression. + + Accessing this attribute may be faster than computing len(self.data) manually. + """ + + if ResourceAttrs.resCompressed in self.attributes: + return self.compressed_info.decompressed_length + else: + return self.length_raw + @property def data(self) -> bytes: """The resource data, decompressed if necessary.