Just a quick heads up: I'm using a trimmed down version of MobiUnpack in the latest
K5 ScreenSavers hack . (I say trimmed down, because I only needed to extract the cover, so I chopped off everything I didn't need
).
It works surprisingly well (after a painful cross-compile of Python 2.7.3 >_<") so far, the only thing of notice I ran into was a MemoryError on the loadSection() of the last section.
I looked at how Calibre was doing it, and saw that it wrapped it in a try/except block to catch OverflowError exceptions (and, indeed, a bit of good old printf debugging seems to point out that after looks like an overflow on the last section).
I tweaked that a bit:
Code:
@@ -267,7 +67,12 @@
def loadSection(self, section):
before, after = self.sections[section:section+2]
self.stream.seek(before)
- return self.stream.read(after - before)
+ try:
+ return self.stream.read(after - before)
+ # This bombs out with a MemoryError on Kindle on the last section (where after overflows)
+ except (OverflowError, MemoryError):
+ self.stream.seek(before)
+ return self.stream.read()
And it does the job, but I was wondering if there wasn't a cleaner way to achieve that... (I feel a bit dirty catching a MemoryError exception...).