def open_str(self, name: str, encoding='utf8'):
"""Open a file in unicode mode or raise FileNotFoundError.
The return value is a StringIO in-memory buffer.
"""
with self:
# File() calls with the VPK object we need directly.
if isinstance(name, VPKFile):
file = name
else:
try:
file = self._ref[name]
except KeyError:
raise FileNotFoundError(name)
# Wrap the data to treat it as bytes, then
# wrap that to decode and clean up universal newlines.
return io.TextIOWrapper(io.BytesIO(file.read()), encoding)
评论列表
文章目录