mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
New MOBI Output: Write a pad record to ensure the first non text record starts at a 4byte boundary
This commit is contained in:
parent
ee1fdd3d0c
commit
fbc770710b
@ -201,6 +201,7 @@ class MobiWriter(object):
|
|||||||
self.text_length = len(text)
|
self.text_length = len(text)
|
||||||
text = StringIO(text)
|
text = StringIO(text)
|
||||||
nrecords = 0
|
nrecords = 0
|
||||||
|
records_size = 0
|
||||||
|
|
||||||
if self.compression != UNCOMPRESSED:
|
if self.compression != UNCOMPRESSED:
|
||||||
self.oeb.logger.info(' Compressing markup content...')
|
self.oeb.logger.info(' Compressing markup content...')
|
||||||
@ -214,9 +215,15 @@ class MobiWriter(object):
|
|||||||
data += pack(b'>B', len(overlap))
|
data += pack(b'>B', len(overlap))
|
||||||
|
|
||||||
self.records.append(data)
|
self.records.append(data)
|
||||||
|
records_size += len(data)
|
||||||
nrecords += 1
|
nrecords += 1
|
||||||
|
|
||||||
self.last_text_record_idx = nrecords
|
self.last_text_record_idx = nrecords
|
||||||
|
self.first_non_text_record_idx = nrecords + 1
|
||||||
|
# Pad so that the next records starts at a 4 byte boundary
|
||||||
|
if records_size % 4 != 0:
|
||||||
|
self.records.append(b'\x00'*(records_size % 4))
|
||||||
|
self.first_non_text_record_idx += 1
|
||||||
|
|
||||||
def read_text_record(self, text):
|
def read_text_record(self, text):
|
||||||
'''
|
'''
|
||||||
@ -338,7 +345,7 @@ class MobiWriter(object):
|
|||||||
|
|
||||||
# 0x40 - 0x43 : Offset of first non-text record
|
# 0x40 - 0x43 : Offset of first non-text record
|
||||||
record0.write(pack(b'>I',
|
record0.write(pack(b'>I',
|
||||||
self.last_text_record_idx + 1))
|
self.first_non_text_record_idx))
|
||||||
|
|
||||||
# 0x44 - 0x4b : title offset, title length
|
# 0x44 - 0x4b : title offset, title length
|
||||||
record0.write(pack(b'>II',
|
record0.write(pack(b'>II',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user