Mercurial > touhou
comparison pytouhou/formats/pbg3.py @ 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 | 1b532e7dd521 |
children | e15672733c93 |
comparison
equal
deleted
inserted
replaced
535:a50c0a1b628f | 536:6b76c9ba3975 |
---|---|
20 PBG3 files are merely a bitstream composed of a header, | 20 PBG3 files are merely a bitstream composed of a header, |
21 a file table, and LZSS-compressed files. | 21 a file table, and LZSS-compressed files. |
22 """ | 22 """ |
23 | 23 |
24 from collections import namedtuple | 24 from collections import namedtuple |
25 from io import BytesIO | |
25 | 26 |
26 from pytouhou.utils.bitstream import BitStream | 27 from pytouhou.utils.bitstream import BitStream |
27 from pytouhou.utils import lzss | 28 from pytouhou.utils import lzss |
28 | 29 |
29 from pytouhou.utils.helpers import get_logger | 30 from pytouhou.utils.helpers import get_logger |
126 def list_files(self): | 127 def list_files(self): |
127 """List files present in the archive.""" | 128 """List files present in the archive.""" |
128 return self.entries.keys() | 129 return self.entries.keys() |
129 | 130 |
130 | 131 |
131 def extract(self, filename, check=False): | 132 def get_file(self, filename, check=False): |
132 """Extract a given file. | 133 """Extract a given file. |
133 | 134 |
134 If “filename” is in the archive, extract it and return its contents. | 135 If “filename” is in the archive, extract it and return its contents. |
135 Otherwise, raise an exception. | 136 Otherwise, raise an exception. |
136 | 137 |
149 for c in self.bitstream.io.read(compressed_size): | 150 for c in self.bitstream.io.read(compressed_size): |
150 value += ord(c) | 151 value += ord(c) |
151 value &= 0xFFFFFFFF | 152 value &= 0xFFFFFFFF |
152 if value != checksum: | 153 if value != checksum: |
153 logger.warn('corrupted data!') | 154 logger.warn('corrupted data!') |
154 return data | 155 return BytesIO(data) |
155 |