def unpack_format_from_file(self, f, seek=None): if seek is not None: timepro.start("seek") f.seek(seek) timepro.end("seek") buf = f.read(self.size) d = self.unpack_format(buf) return d
def read_directory_entry(self, offset): """May return either a Redirect or Article entry depending on flag""" timepro.start("seek") self.f.seek(offset) timepro.end("seek") timepro.start("read(2)") buf = self.f.read(2) timepro.end("read(2)") fields = struct.unpack('H', buf) if fields[0] == 0xffff: # Then redirect return dict(self.redirectEntryFormat.unpack_from_file(self.f, offset)) else: return dict(self.articleEntryFormat.unpack_from_file(self.f, offset))
def read_directory_entry(self, offset): """May return either a Redirect or Article entry depending on flag""" timepro.start("seek") self.f.seek(offset) timepro.end("seek") timepro.start("read(2)") buf = self.f.read(2) timepro.end("read(2)") fields = struct.unpack('H', buf) if fields[0] == 0xffff: # Then redirect return dict( self.redirectEntryFormat.unpack_from_file(self.f, offset)) else: return dict( self.articleEntryFormat.unpack_from_file(self.f, offset))
def _decompress(self, chunk_size=32000): """Decompresses the cluster if compression flag was found. Stores uncompressed results internally.""" if not self.compressed: return self.file_buf.seek(self.ptr + 1) # Store uncompressed cluster data for use as uncompressed data self.uncomp_buf = StringIO() decomp = lzma.LZMADecompressor() while not decomp.eof: timepro.start("file_buf read") comp_data = self.file_buf.read(chunk_size) timepro.end("file_buf read") timepro.start("decompress") uncomp_data = decomp.decompress(comp_data) timepro.end("decompress") timepro.start("write") self.uncomp_buf.write(uncomp_data) timepro.end("write") return self.uncomp_buf