mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
py3: make SNB output work
variables initialized as implicit bytes '' on python2, should be b'' python2 used integer division, make this explicit on python3
This commit is contained in:
parent
6583e1e2fb
commit
7fbf985870
@ -23,7 +23,7 @@ class BlockData:
|
||||
|
||||
class SNBFile:
|
||||
|
||||
MAGIC = 'SNBP000B'
|
||||
MAGIC = b'SNBP000B'
|
||||
REV80 = 0x00008000
|
||||
REVA3 = 0x00A3A3A3
|
||||
REVZ1 = 0x00000000
|
||||
@ -75,7 +75,7 @@ class SNBFile:
|
||||
if f.attr & 0x41000000 == 0x41000000:
|
||||
# Compressed Files
|
||||
if uncompressedData is None:
|
||||
uncompressedData = ""
|
||||
uncompressedData = b""
|
||||
for i in range(self.plainBlock):
|
||||
bzdc = bz2.BZ2Decompressor()
|
||||
if (i < self.plainBlock - 1):
|
||||
@ -106,7 +106,7 @@ class SNBFile:
|
||||
raise Exception("Invalid file")
|
||||
|
||||
def ParseFile(self, vfat, fileCount):
|
||||
fileNames = vfat[fileCount*12:].split('\0')
|
||||
fileNames = vfat[fileCount*12:].split(b'\0')
|
||||
for i in range(fileCount):
|
||||
f = FileStream()
|
||||
(f.attr, f.fileNameOffset, f.fileSize) = struct.unpack('>iii', vfat[i * 12 : (i+1)*12])
|
||||
@ -114,8 +114,8 @@ class SNBFile:
|
||||
self.files.append(f)
|
||||
|
||||
def ParseTail(self, vtail, fileCount):
|
||||
self.binBlock = (self.binStreamSize + 0x8000 - 1) / 0x8000
|
||||
self.plainBlock = (self.plainStreamSizeUncompressed + 0x8000 - 1) / 0x8000
|
||||
self.binBlock = (self.binStreamSize + 0x8000 - 1) // 0x8000
|
||||
self.plainBlock = (self.plainStreamSizeUncompressed + 0x8000 - 1) // 0x8000
|
||||
for i in range(self.binBlock + self.plainBlock):
|
||||
block = BlockData()
|
||||
(block.Offset,) = struct.unpack('>i', vtail[i * 4 : (i+1) * 4])
|
||||
@ -204,13 +204,13 @@ class SNBFile:
|
||||
vmbrp1 = struct.pack('>8siiii', SNBFile.MAGIC, SNBFile.REV80, SNBFile.REVA3, SNBFile.REVZ1, len(self.files))
|
||||
|
||||
# Create VFAT & file stream
|
||||
vfat = ''
|
||||
fileNameTable = ''
|
||||
plainStream = ''
|
||||
binStream = ''
|
||||
vfat = b''
|
||||
fileNameTable = b''
|
||||
plainStream = b''
|
||||
binStream = b''
|
||||
for f in self.files:
|
||||
vfat += struct.pack('>iii', f.attr, len(fileNameTable), f.fileSize)
|
||||
fileNameTable += (f.fileName + '\0')
|
||||
fileNameTable += (f.fileName + b'\0')
|
||||
|
||||
if f.attr & 0x41000000 == 0x41000000:
|
||||
# Plain Files
|
||||
@ -236,22 +236,22 @@ class SNBFile:
|
||||
binBlockOffset = 0x2C + len(vfatCompressed)
|
||||
plainBlockOffset = binBlockOffset + len(binStream)
|
||||
|
||||
binBlock = (len(binStream) + 0x8000 - 1) / 0x8000
|
||||
binBlock = (len(binStream) + 0x8000 - 1) // 0x8000
|
||||
# plainBlock = (len(plainStream) + 0x8000 - 1) / 0x8000
|
||||
|
||||
offset = 0
|
||||
tailBlock = ''
|
||||
tailBlock = b''
|
||||
for i in range(binBlock):
|
||||
tailBlock += struct.pack('>i', binBlockOffset + offset)
|
||||
offset += 0x8000
|
||||
tailRec = ''
|
||||
tailRec = b''
|
||||
for f in self.files:
|
||||
t = 0
|
||||
if f.IsBinary():
|
||||
t = 0
|
||||
else:
|
||||
t = binBlock
|
||||
tailRec += struct.pack('>ii', f.contentOffset / 0x8000 + t, f.contentOffset % 0x8000)
|
||||
tailRec += struct.pack('>ii', f.contentOffset // 0x8000 + t, f.contentOffset % 0x8000)
|
||||
|
||||
# Write binary stream
|
||||
outputFile.write(binStream)
|
||||
|
Loading…
x
Reference in New Issue
Block a user