mirror of
git://github.com/kovidgoyal/calibre.git
synced 2026-05-02 21:03:17 +02:00
Allow passing in file objects to add_file()
This commit is contained in:
parent
1255f81cfd
commit
7bf79bd650
1 changed files with 4 additions and 1 deletions
|
|
@ -335,7 +335,10 @@ def add_file(self, name, data, media_type=None, spine_index=None, modify_name_if
|
|||
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
|
||||
|
|
|
|||
Loading…
Reference in a new issue