def save(self, filename):
"""Save book to a file."""
if pathlib.Path(filename).exists():
raise FileExistsError
self._write_spine()
self._write('container.xml', 'META-INF/container.xml')
self._write_toc()
with open(str(self.path / 'mimetype'), 'w') as file:
file.write('application/epub+zip')
with zipfile.ZipFile(filename, 'w') as archive:
archive.write(
str(self.path / 'mimetype'), 'mimetype',
compress_type=zipfile.ZIP_STORED)
for file in self.path.rglob('*.*'):
archive.write(
str(file), str(file.relative_to(self.path)),
compress_type=zipfile.ZIP_DEFLATED)
###########################################################################
# Private Methods
###########################################################################
评论列表
文章目录