Skip to content

Instantly share code, notes, and snippets.

@bitsgalore
Last active August 28, 2020 14:57
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save bitsgalore/da04413787931d20a8bf to your computer and use it in GitHub Desktop.
How to package an epub file using InfoZip

Background

An EPUB is just a ZIP container, but using a ZIP tool directly on a directory with content documents won't usually result in a valid EPUB. This is because the standard requires that:

  1. The mimetype resource must appear as the first file in the container
  2. The mimetype resource must be uncompressed

So to meet these requirements we must ZIP the files in a special way. This gist describes how to do this with InfoZip (which is the default ZIP tool on most Linux systems).

Let's suppose all content files are in a directory called /home/johan/epubPolicyTests/content/epub20_minimal/.

Step 1: go to the content file directory

cd /home/johan/epubPolicyTests/content/epub20_minimal/

Step 2: create new ZIP file, add mimetype resource without compression

zip -X0 /home/johan/epubPolicyTests/build/epub20_minimal.epub mimetype

Step 3: add remaining files to ZIP file with compression

zip -rDX9 /home/johan/epubPolicyTests/build/epub20_minimal.epub * -x mimetype

Step 4: test with epubcheck

epubcheck /home/johan/epubPolicyTests/build/epub20_minimal.epub

Done!

source

Adapted from http://www.mobileread.com/forums/showpost.php?s=5ebefd2d1551601ab91386c12853dfc6&p=581649&postcount=1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment