From 7bf79bd6500bdb4c38f2b903177daec54a7a5977 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 9 Oct 2016 14:57:09 +0530 Subject: [PATCH] Allow passing in file objects to add_file() --- src/calibre/ebooks/oeb/polish/container.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/calibre/ebooks/oeb/polish/container.py b/src/calibre/ebooks/oeb/polish/container.py index bf585b4626..9ea7c0a408 100644 --- a/src/calibre/ebooks/oeb/polish/container.py +++ b/src/calibre/ebooks/oeb/polish/container.py @@ -335,7 +335,10 @@ class Container(ContainerBase): # {{{ if not os.path.exists(base): os.makedirs(base) with lopen(path, 'wb') as f: - f.write(data) + if hasattr(data, 'read'): + shutil.copyfileobj(data, f) + else: + f.write(data) mt = media_type or self.guess_type(name) self.name_path_map[name] = path self.mime_map[name] = mt