mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
py3: make rb output work
This commit is contained in:
parent
336d4054d1
commit
f2009fd991
@ -6,7 +6,7 @@ __docformat__ = 'restructuredtext en'
|
||||
|
||||
import os
|
||||
|
||||
HEADER = '\xb0\x0c\xb0\x0c\x02\x00NUVO\x00\x00\x00\x00'
|
||||
HEADER = b'\xb0\x0c\xb0\x0c\x02\x00NUVO\x00\x00\x00\x00'
|
||||
|
||||
|
||||
class RocketBookError(Exception):
|
||||
|
@ -73,13 +73,13 @@ class RBWriter(object):
|
||||
out_stream.write(struct.pack('<I', page_count))
|
||||
offset = out_stream.tell() + (len(toc_items) * 44)
|
||||
for item in toc_items:
|
||||
out_stream.write(item.name)
|
||||
out_stream.write(item.name.encode('utf-8'))
|
||||
out_stream.write(struct.pack('<I', item.size))
|
||||
out_stream.write(struct.pack('<I', offset))
|
||||
out_stream.write(struct.pack('<I', item.flags))
|
||||
offset += item.size
|
||||
|
||||
out_stream.write(info[0][1])
|
||||
out_stream.write(info[0][1].encode('utf-8'))
|
||||
|
||||
self.log.debug('Writing compressed RB HTHML...')
|
||||
# Compressed text with proper heading
|
||||
@ -92,7 +92,10 @@ class RBWriter(object):
|
||||
|
||||
self.log.debug('Writing images...')
|
||||
for item in hidx+images:
|
||||
out_stream.write(item[1])
|
||||
w = item[1]
|
||||
if not isinstance(w, bytes):
|
||||
w = w.encode('utf-8')
|
||||
out_stream.write(w)
|
||||
|
||||
total_size = out_stream.tell()
|
||||
out_stream.seek(0x1c)
|
||||
@ -104,7 +107,7 @@ class RBWriter(object):
|
||||
size = len(text)
|
||||
|
||||
pages = []
|
||||
for i in range(0, (len(text) + TEXT_RECORD_SIZE-1) / TEXT_RECORD_SIZE):
|
||||
for i in range(0, (len(text) + TEXT_RECORD_SIZE-1) // TEXT_RECORD_SIZE):
|
||||
zobj = zlib.compressobj(9, zlib.DEFLATED, 13, 8, 0)
|
||||
pages.append(zobj.compress(text[i * TEXT_RECORD_SIZE : (i * TEXT_RECORD_SIZE) + TEXT_RECORD_SIZE]) + zobj.flush())
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user