mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 02:34:06 -04:00
Allow passing in bytestrings as replacements, not just file like objects
This commit is contained in:
parent
ca2d3986cd
commit
cde906b936
@ -1476,7 +1476,10 @@ def safe_replace(zipstream, name, datastream, extra_replacements={},
|
|||||||
if isinstance(obj.filename, unicode):
|
if isinstance(obj.filename, unicode):
|
||||||
obj.flag_bits |= 0x16 # Set isUTF-8 bit
|
obj.flag_bits |= 0x16 # Set isUTF-8 bit
|
||||||
if obj.filename in names:
|
if obj.filename in names:
|
||||||
ztemp.writestr(obj, replacements[obj.filename].read())
|
r = replacements[obj.filename]
|
||||||
|
if not isinstance(r, bytes):
|
||||||
|
r = r.read()
|
||||||
|
ztemp.writestr(obj, r)
|
||||||
found.add(obj.filename)
|
found.add(obj.filename)
|
||||||
else:
|
else:
|
||||||
ztemp.writestr(obj, z.read_raw(obj), raw_bytes=True)
|
ztemp.writestr(obj, z.read_raw(obj), raw_bytes=True)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user