Re building epubs

A while back, in one of Apple’s many bizarre OS shifts, they screwed with the compress file function in finder. What this means is that epubs (which are essentially zip files) no longer package or unpackage correctly. Attempt it and you end up with a rather bizarre cpgz file.

I came across this lovely post on how to use terminal to attain correct results and thought I would repost it for posterity:

Open Terminal Services: Applications/Utilities/Terminal Services and go to your file – I usually put a folder on the desktop with the ePub file in it, so to get to it, I use the following:

cd desktop/epub_folder

If you are unzipping the folder, use this command:

unzip epubfilename.epub

(At this point, if you’re doing a fixed format file, you will put Apple’s display options file inside the META-INF folder. This is also the only way I know of to add audio and video files to an ePUB, and to make all the updates required to make these files work.)

When you zip the ePub file back up, it’s important to zip an ePub up in the correct order. mimetype goes in first, with no compression. We’re also going to rename the file so we know we’re creating a new version. Here’s how:

zip -X newepubname.epub mimetype

Next up is the META-INF folder. You also want to suppress adding any MAC O/S .DS_Store files.

zip -rg newepubname.epub META-INF -x \*.DS_Store

Next is the OEBPS folder:

zip -rg newepubname.epub OEBPS -x \*.DS_Store

That’s it!