mirror of
https://github.com/dgelessus/python-rsrcfork.git
synced 2025-01-01 07:29:40 +00:00
Rewrite Resource methods using stream API where appropriate
This commit is contained in:
parent
61247ec783
commit
664e992fa3
@ -130,10 +130,12 @@ class Resource(object):
|
|||||||
|
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
try:
|
try:
|
||||||
data = self.data
|
with self.open() as f:
|
||||||
|
data = f.read(33)
|
||||||
except compress.DecompressError:
|
except compress.DecompressError:
|
||||||
decompress_ok = False
|
decompress_ok = False
|
||||||
data = self.data_raw
|
with self.open_raw() as f:
|
||||||
|
data = f.read(33)
|
||||||
else:
|
else:
|
||||||
decompress_ok = True
|
decompress_ok = True
|
||||||
|
|
||||||
@ -207,7 +209,8 @@ class Resource(object):
|
|||||||
try:
|
try:
|
||||||
return self._compressed_info
|
return self._compressed_info
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
self._compressed_info = compress.common.CompressedHeaderInfo.parse(self.data_raw)
|
with self.open_raw() as f:
|
||||||
|
self._compressed_info = compress.common.CompressedHeaderInfo.parse_stream(f)
|
||||||
return self._compressed_info
|
return self._compressed_info
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
@ -244,7 +247,9 @@ class Resource(object):
|
|||||||
try:
|
try:
|
||||||
return self._data_decompressed
|
return self._data_decompressed
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
self._data_decompressed = compress.decompress_parsed(self.compressed_info, self.data_raw[self.compressed_info.header_length:])
|
with self.open_raw() as f:
|
||||||
|
f.seek(self.compressed_info.header_length)
|
||||||
|
self._data_decompressed = b"".join(compress.decompress_stream_parsed(self.compressed_info, f))
|
||||||
return self._data_decompressed
|
return self._data_decompressed
|
||||||
else:
|
else:
|
||||||
return self.data_raw
|
return self.data_raw
|
||||||
|
Loading…
Reference in New Issue
Block a user