[epub] 打包一个epub文件

 

Packing an EPUB file is more specific than just creating a ZIP archive. Because EPUB is a standard, it has a strict internal structure and a specific "first-file" rule that must be followed for the file to be valid. 

Here is how to pack your EPUB manually or using tools.


1. The "Magic" Rules for EPUB

To pass validation, your EPUB must meet these three conditions:

  • The mimetype file must be first: It must be the very first file in the ZIP archive.

  • No compression on mimetype: The mimetype file must be stored (0% compression), while everything else can be compressed.

  • No extra fields: The mimetype file cannot have any extra ZIP headers or "hidden" metadata.


2. Using Command Line

This is the most reliable way to ensure the mimetype is handled correctly. Open your terminal/command prompt inside your book's root folder.

On macOS / Linux

Run these two commands in order:

  1. Pack the mimetype (uncompressed):

    zip -0Xq mybook.epub mimetype

  2. Pack everything else (compressed):

    zip -9rXq mybook.epub * -x mimetype

(Note: -0 means no compression; -X excludes extra file attributes like .DS_Store.)

 
 

 

posted @ 2026-01-21 09:01  profesor  阅读(1)  评论(0)    收藏  举报