mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix #1147 (epub-meta compresses the file mimetype when rebuilding an epub)
This commit is contained in:
parent
bcb4e20f40
commit
1e9c18b79b
@ -250,7 +250,7 @@ class Splitter(LoggingInterface):
|
|||||||
'//p',
|
'//p',
|
||||||
'//br',
|
'//br',
|
||||||
):
|
):
|
||||||
elems = root.xpath(path)
|
elems = root.xpath(path, namespaces={'re':'http://exslt.org/regular-expressions'})
|
||||||
elem = pick_elem(elems)
|
elem = pick_elem(elems)
|
||||||
if elem is not None:
|
if elem is not None:
|
||||||
try:
|
try:
|
||||||
|
@ -1315,12 +1315,12 @@ def safe_replace(zipstream, name, datastream):
|
|||||||
and re-creating the zipfile. This is neccessary because :method:`ZipFile.replace`
|
and re-creating the zipfile. This is neccessary because :method:`ZipFile.replace`
|
||||||
sometimes created corrupted zip files.
|
sometimes created corrupted zip files.
|
||||||
|
|
||||||
:param zipstream: Stream from a zip file
|
:param zipstream: Stream from a zip file
|
||||||
:param name: The name of the file to replace
|
:param name: The name of the file to replace
|
||||||
:param datastream: The data to replace the file with.
|
:param datastream: The data to replace the file with.
|
||||||
'''
|
'''
|
||||||
z = ZipFile(zipstream, 'r')
|
z = ZipFile(zipstream, 'r')
|
||||||
names = z.namelist()
|
names = z.infolist()
|
||||||
with TemporaryDirectory('_zipfile_replace') as tdir:
|
with TemporaryDirectory('_zipfile_replace') as tdir:
|
||||||
z.extractall(path=tdir)
|
z.extractall(path=tdir)
|
||||||
zipstream.seek(0)
|
zipstream.seek(0)
|
||||||
@ -1328,12 +1328,12 @@ def safe_replace(zipstream, name, datastream):
|
|||||||
z = ZipFile(zipstream, 'w')
|
z = ZipFile(zipstream, 'w')
|
||||||
path = os.path.join(tdir, *name.split('/'))
|
path = os.path.join(tdir, *name.split('/'))
|
||||||
shutil.copyfileobj(datastream, open(path, 'wb'))
|
shutil.copyfileobj(datastream, open(path, 'wb'))
|
||||||
for name in names:
|
for info in names:
|
||||||
current = os.path.join(tdir, *name.split('/'))
|
current = os.path.join(tdir, *info.filename.split('/'))
|
||||||
if os.path.isdir(current):
|
if os.path.isdir(current):
|
||||||
z.writestr(name+'/', '', 0700)
|
z.writestr(info.filename+'/', '', 0700)
|
||||||
else:
|
else:
|
||||||
z.write(current, name)
|
z.write(current, info.filename, compress_type=info.compress_type)
|
||||||
z.close()
|
z.close()
|
||||||
|
|
||||||
class PyZipFile(ZipFile):
|
class PyZipFile(ZipFile):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user