THE LAST STEP IN MAKING an epub3 is compressing the components and bundling them together into a single file. This process is called zipping. It’s hard to do this correctly with general-purpose zip programs because the epub3 standard requires the files to be bundled in a tricky way (the mimetype file must come first and must be uncompressed).
There are epub programs that handle this tricky detail, but none of them works exactly the way I wanted so I wrote this one for myself. Because this program fits my proclivities precisely, it lets me create epub’s faster and makes the job more enjoyable. You’re welcome to download it and use it too.
Step one: Put all the component files of your epub3 in a folder. Arrange them according to the epub3 guidelines with mimetype in the root, container.xml in META-INF, and the rest of the files in OEBPS.
Step two: Run ZipEpub.exe with two command-line arguments. The first argument is the path of the folder that you made in step one. The second argument is the path of the epub3 file that you want to create.
You can type the command line by hand in a command window, enter it in a shortcut, run it from a batch file, instruct some other program to run it, etc.
Suppose your component files are in c:\book\raw-files and you want to create c:\book\masterpiece.epub. Your command line would be:
zipepub c:\book\raw-files c:\book\masterpiece.epub
As always with Windows, if an argument contains spaces enclose it in quotation marks.
Your feedback is welcome. If you find any bugs in the program, please let me know in the comments below so I can fix them.
The complete syntax is:
zipepub 〈input〉 〈output〉 [-o] [-t〈datetime〉]
Input is the path of the directory that contains the files that your epub3 is made from.
Output is the path of the epub3 file that you wish to create.
-o is optional. If you include it, ZipEpub opens the created epub3 in your default reader so you can check the results. (Set the default reader with Windows.)
-t is optional. Use this to set the timestamps (the dates and times) of the epub file and the files inside it. If you omit this, the epub will be set to the time when you create it and the component files will be marked inside the epub with their last-modified times. -t must be followed immediately (no space) by a timestamp in ISO 8601 format. Here are some examples:
Append Z to indicate UTC time. Omit it to indicate your local time zone. Please note that this timezone setting works correctly with the epub file but unfortunately, due to the design of the zip format, timestamps on the component files inside may be off by as much as 23 hours.
This program runs only on Windows. It creates only epub3’s. There are no limits on sizes or numbers of files.
There is no way to add a file to an existing epub; the program always creates the whole epub from scratch every time it runs. I don’t think this will be a problem for anyone because the program is extremely fast.
On success, the program writes a string to stdout (visible to users in a command window) that includes the characters “Success!” and returns zero.
On failure, the program writes an error message to stdout that includes the characters “***Error:” and returns a non-zero value.
The program deletes the output (epub) file and recreates it from scratch every time it runs. This may not be apparent from the file times shown by Windows Explorer.
Like almost every zip program under the sun, this one uses code from the zlib library to compress files.
The program is written in unmanaged C and C++ and compiled with Visual Studio 2022.
This page was first published on April 4, 2022 and last revised on April 6, 2022.