mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Allow passing in file objects to add_file()
This commit is contained in:
parent
1255f81cfd
commit
7bf79bd650
@ -335,7 +335,10 @@ class Container(ContainerBase): # {{{
|
|||||||
if not os.path.exists(base):
|
if not os.path.exists(base):
|
||||||
os.makedirs(base)
|
os.makedirs(base)
|
||||||
with lopen(path, 'wb') as f:
|
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)
|
mt = media_type or self.guess_type(name)
|
||||||
self.name_path_map[name] = path
|
self.name_path_map[name] = path
|
||||||
self.mime_map[name] = mt
|
self.mime_map[name] = mt
|
||||||
|
Loading…
x
Reference in New Issue
Block a user