From 0aeec73eae1aea3ed03e83fb1610030cf509c49a Mon Sep 17 00:00:00 2001 From: David Forrester Date: Thu, 5 Sep 2013 15:39:44 +1000 Subject: [PATCH] Kobo driver: Sideloaded kepubs not added from device properly When a sideloaded kepub is added from a Kobo device to the calibre library, it is added as an epub, but the file copied is corrupt. Fixes #1221035 [Sideloaded kepubs not added to library correctly](https://bugs.launchpad.net/calibre/+bug/1221035) --- src/calibre/devices/kobo/driver.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/calibre/devices/kobo/driver.py b/src/calibre/devices/kobo/driver.py index 13f2f9236d..9a86f61ef2 100644 --- a/src/calibre/devices/kobo/driver.py +++ b/src/calibre/devices/kobo/driver.py @@ -13,7 +13,7 @@ Originally developed by Timothy Legge . Extended to support Touch firmware 2.0.0 and later and newer devices by David Forrester ''' -import os, time +import os, time, shutil from contextlib import closing from calibre.devices.usbms.books import BookList @@ -1001,9 +1001,10 @@ class KOBO(USBMS): ''' for idx, path in enumerate(paths): if path.find('kepub') >= 0: - with closing(open(path)) as r: + with closing(open(path, 'rb')) as r: tf = PersistentTemporaryFile(suffix='.epub') - tf.write(r.read()) + shutil.copyfileobj(r, tf) +# tf.write(r.read()) paths[idx] = tf.name return paths