# HG changeset patch # User Emmanuel Gil Peyrot # Date 1396716828 -7200 # Node ID 6b76c9ba3975719563ff4eda54111d14c5124daf # Parent a50c0a1b628f9a909285909c8309151aae9f7f89 Make archives return files by default, instead of bytes. diff --git a/pytouhou/formats/pbg3.py b/pytouhou/formats/pbg3.py --- a/pytouhou/formats/pbg3.py +++ b/pytouhou/formats/pbg3.py @@ -22,6 +22,7 @@ a file table, and LZSS-compressed files. """ from collections import namedtuple +from io import BytesIO from pytouhou.utils.bitstream import BitStream from pytouhou.utils import lzss @@ -128,7 +129,7 @@ class PBG3(object): return self.entries.keys() - def extract(self, filename, check=False): + def get_file(self, filename, check=False): """Extract a given file. If “filename” is in the archive, extract it and return its contents. @@ -151,5 +152,4 @@ class PBG3(object): value &= 0xFFFFFFFF if value != checksum: logger.warn('corrupted data!') - return data - + return BytesIO(data) diff --git a/pytouhou/resource/loader.py b/pytouhou/resource/loader.py --- a/pytouhou/resource/loader.py +++ b/pytouhou/resource/loader.py @@ -15,7 +15,6 @@ import os from glob import glob from itertools import chain -from io import BytesIO from pytouhou.formats import WrongFormatError from pytouhou.formats.pbg3 import PBG3 @@ -55,10 +54,8 @@ class Directory(object): return file_list - def extract(self, name): - with open(os.path.join(self.path, str(name)), 'rb') as file: - contents = file.read() - return contents + def get_file(self, name): + return open(os.path.join(self.path, str(name)), 'rb') @@ -124,16 +121,9 @@ class Loader(object): self.known_files[name] = archive_description - def get_file_data(self, name): - with self.known_files[name].open() as archive: - content = archive.extract(name) - return content - - def get_file(self, name): with self.known_files[name].open() as archive: - content = archive.extract(name) - return BytesIO(content) + return archive.get_file(name) def get_anm(self, name):