py3: make rb output work

This commit is contained in:
Eli Schwartz 2019-04-22 03:20:59 -04:00
parent 336d4054d1
commit f2009fd991
No known key found for this signature in database
GPG Key ID: CEB167EFB5722BD6
2 changed files with 8 additions and 5 deletions

View File

@ -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):

View File

@ -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())