예제 #1
0
파일: reader.py 프로젝트: smdx023/calibre
    def __init__(self, header, stream, log, options):
        self.stream = stream
        self.log = log
        self.options = options

        self.sections = []
        for i in range(header.num_sections):
            self.sections.append(header.section_data(i))

        self.header_record = HeaderRecord(self.section_data(0))

        vmajor = (self.header_record.version & 0x0000FF00) >> 8
        vminor = self.header_record.version & 0x000000FF
        if vmajor < 1 or (vmajor == 1 and vminor < 40):
            raise zTXTError(
                'Unsupported ztxt version (%i.%i). Only versions newer than %i.%i are supported.'
                % (vmajor, vminor, SUPPORTED_VERSION[0], SUPPORTED_VERSION[1]))

        if (self.header_record.flags & 0x01) == 0:
            raise zTXTError(
                'Only compression method 1 (random access) is supported')

        self.log.debug('Foud ztxt version: %i.%i' % (vmajor, vminor))

        # Initialize the decompressor
        self.uncompressor = zlib.decompressobj()
        self.uncompressor.decompress(self.section_data(1))
예제 #2
0
파일: reader.py 프로젝트: Farb/calibre
    def __init__(self, header, stream, log, options):
        self.stream = stream
        self.log = log
        self.options = options

        self.sections = []
        for i in range(header.num_sections):
            self.sections.append(header.section_data(i))

        self.header_record = HeaderRecord(self.section_data(0))

        vmajor = (self.header_record.version & 0x0000FF00) >> 8
        vminor = self.header_record.version & 0x000000FF
        if vmajor < 1 or (vmajor == 1 and vminor < 40):
            raise zTXTError('Unsupported ztxt version (%i.%i). Only versions newer than %i.%i are supported.' %
                            (vmajor, vminor, SUPPORTED_VERSION[0], SUPPORTED_VERSION[1]))

        if (self.header_record.flags & 0x01) == 0:
            raise zTXTError('Only compression method 1 (random access) is supported')

        self.log.debug('Foud ztxt version: %i.%i' % (vmajor, vminor))

        # Initalize the decompressor
        self.uncompressor = zlib.decompressobj()
        self.uncompressor.decompress(self.section_data(1))