changeset 536:6b76c9ba3975

Make archives return files by default, instead of bytes.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sat, 05 Apr 2014 18:53:48 +0200
parents a50c0a1b628f
children 63440d1e0717
files pytouhou/formats/pbg3.py pytouhou/resource/loader.py
diffstat 2 files changed, 6 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- 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)
--- 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):