I am using the C# library DotNetZip (Ionic.Zip and Ionic.Zlib) to generate an ebook from a directory. Directory looks like this:

BookName
|
|___content/
|       images/
|       css/
|       (html pages, .ops, .ncx)
|
|___META-INF/
|       container.xml
|
|___mimetype

The code to generate the archive looks like this:

using (ZipFile zip = new ZipFile(pathTemp + ".epub"))
{
    zip.RemoveSelectedEntries("*.*");
    zip.AddFile(mimetype, "").CompressionLevel = CompressionLevel.None;
    zip.AddDirectory(pathTemp + "\\content", "content");
    zip.AddDirectory(pathTemp + "\\META-INF", "META-INF");
    zip.Save();
}

When I run it through the EPUB Validator, it throws this error:

The mimetype file has an extra field of length 36. The use of the extra field feature of the ZIP format is not permitted for the mimetype file.

I'm not compressing the mimetype file, so I don't know what is happening.

UPDATE: This problem has been solved; see the solution here.

  • This problem has been solved - see the solution here. – zuddsy Nov 28 '15 at 1:29

I'm responsible for an attempt to improve this error message, see https://github.com/IDPF/epubcheck/pull/497 for details. Essentially your Zip packer puts some application or operating system specific stuff into the file, which breaks EPUB mimetype magic number support.

  • Use the zip -X flag to exclude the extra OS flags, which makes epubcheck stop complaining about the mimetype file. – bjnord Jul 8 '17 at 21:02

Ive also had some problems with compression of the mimetype file. What I ended up doing was adding the entry myself from a byte[].

using (ZipOutputStream zs = new ZipOutputStream(pathTemp + ".epub"))
 {
  var o = zs.PutNextEntry("mimetype");
  o.CompressionLevel = CompressionLevel.None;
  byte[] mimetype  = System.Text.Encoding.ASCII.GetBytes("application/epub+zip");
  zs.Write(mimetype, 0, mimetype.Length);
 }

using (ZipFile zip = new ZipFile(pathTemp + ".epub"))
 {
  zip.RemoveSelectedEntries("*.*");
  zip.AddDirectory(pathTemp + "\\content", "content");
  zip.AddDirectory(pathTemp + "\\META-INF", "META-INF");
  zip.Save();
 }

This should fix it for you.

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.