Although the underlying stream is already buffered, the extra
BufferedReader wrapper around the SubStream results in a noticeable
performance improvement.
This way all reads performed on a resource data stream are forwarded
to the underlying resource file stream, with the read offsets and
lengths adjusted appropriately.
The old functions/methods still exist, so that they continue to raise
the same exceptions as before (which are different depending on
context), but they now use the same implementation internally.
The _references map now stores Resource objects directly, instead of
constructing them only when they are looked up. Resource objects are
now lazy themselves, so the previous lazy resource creation mechanism
is redundant.
_LazyResourceMap is now a simple read-only wrapper around an existing
map. The custom class is now only used to provide a specialized repr.
The reading of resource name and data is now performed in the Resource
class (lazily, when the respective attributes are accessed) instead of
in ResourceFile._LazyResourceMap.
Previously, the types of instance attributes were annotated with the
first assignment of each attribute. The standard way to annotate
instance attributes is to do so at class level without assigning any
value.
According to https://bugs.python.org/issue35089, typing.io should not
be used anymore, and the types that it contains should be accessed
through the main typing module instead.
For compressed resources, the value of the length attribute can be
accessed much more quickly than the data itself (because it only
requires parsing the header, rather than decompressing the entire
data). This is used to speed up listing of compressed resources on the
command line.
The length_raw attribute is added for symmetry, although it is not
specifically optimized in any case yet.
The broken non-seeking read implementation of ResourceFile is removed,
and non-seekable streams are now handled by reading the entire stream
data first and wrapping it in a BytesIO to make it seekable.
The manual selection of seeking/non-seeking reading has been removed as
well, since it is no longer needed and was already nearly useless.
When using ResourceFork.open, the stream is still closed when the
ResourceFile is closed, because the user has no access to the stream.
This matches the behavior of modules like zipfile and tarfile, which
close their underlying streams if they created them themselves, but not
if they were supplied by the user.