对于像我这样正在寻找其他方法的人来说,我想补充一点,Jaime Olivares 的 ZipStorer 类是一个很好的选择。您可以将代码直接复制到您的项目中,并且很容易在“deflate”和“store”之间进行选择。
https://github.com/jaime-olivares/zipstorer
这是我创建 EPUB 的代码:
Dictionary<string, string> FilesToZip = new Dictionary<string, string>()
{
{ ConfigPath + @"mimetype", @"mimetype"},
{ ConfigPath + @"container.xml", @"META-INF/container.xml" },
{ OutputFolder + Name.Output_OPF_Name, @"OEBPS/" + Name.Output_OPF_Name},
{ OutputFolder + Name.Output_XHTML_Name, @"OEBPS/" + Name.Output_XHTML_Name},
{ ConfigPath + @"style.css", @"OEBPS/style.css"},
{ OutputFolder + Name.Output_NCX_Name, @"OEBPS/" + Name.Output_NCX_Name}
};
using (ZipStorer EPUB = ZipStorer.Create(OutputFolder + "book.epub", ""))
{
bool First = true;
foreach (KeyValuePair<string, string> File in FilesToZip)
{
if (First) { EPUB.AddFile(ZipStorer.Compression.Store, File.Key, File.Value, ""); First = false; }
else EPUB.AddFile(ZipStorer.Compression.Deflate, File.Key, File.Value, "");
}
}
此代码创建一个完全有效的 EPUB 文件。但是,如果您不需要担心验证,似乎大多数电子阅读器都会接受带有“deflate”mimetype 的 EPUB。因此,我之前使用 .NET 的 ZipArchive 的代码生成了在 Adobe Digital Editions 和 PocketBook 中工作的 EPUB。