mimetype file compression

7 posts / 0 new
Last post

I am trying to create my own epub file, I have created the mimetype file as stated in
http://idpf.org/epub/30/spec/epub30-ocf.html section 3.3

"OCF ZIP Containers must include a mimetype file as the first file in the Container, and the contents of this file must be the MIME type string application/epub+zip.

The contents of the mimetype file must not contain any leading padding or whitespace, must not begin with the Unicode signature (or Byte Order Mark), and the case of the MIME type string must be exactly as presented above. The mimetype file additionally must be neither compressed nor encrypted, and there must not be an extra field in its ZIP header."

I have built the file, simple.

I am having trouble with the concept of compressing, I am sure it is a simple one. If you would help me, how do i go about doing this? Every file I put in a .zip container gets compressed.
I am using file roller for gnome 2.30.1.1 . Ubuntu 10.04 LTS

Not all files in a zip container have to be compressed, or compressed the same way, and setting "stored" -- or whatever equivalent option the archiving program uses, such as "0" -- for the compression method will add a file without compressing it. I don't have File Roller, but from what  I was able to find, and your experience, it doesn't sound like you get the option to change the compression method per file.

You could find another archiving program, but what might be easier is to use epubcheck. It includes the option to create the container for you from the uncompressed directory where you've stored your publication using the '-save' command.

It's used in the EPUB 3 samples project to rebuild the publications, for example. You can view the shell script that invokes it to create the archive here for an idea of how to call it.

Hope this helps.

""Not all files in a zip container have to be compressed, or compressed the same way, and setting "stored" -- or whatever equivalent option the archiving program uses, such as "0" -- for the compression method will add a file without compressing it. I don't have File Roller, but from what I was able to find, and your experience, it doesn't sound like you get the option to change the compression method per file.""

which archiving programs are you using that have "File stored" options? and how do you get to that setting? every archiver that i DL does not have those options

I'm not the best help for GUIs. Between epubcheck and a C# program I wrote using ZipLib, that's typically all I use to bundle epubs (and I'm usually on Windows, as you might guess, so recommending WinRAR probably won't make you happy!). I'm surprised you don't get the option to pick compression, but it's probably simpler to use the zip program directly from a shell if you can't find one or get epubcheck to run.

Grabbing one of the books in the epub samples project, I was able to rebuild as follows (using ubuntu, obviously, but that shouldn't matter):

mgarrish@ubuntu-matt:~/Downloads$ zip -0 -X test.zip mimetype
  adding: mimetype (stored 0%)
mgarrish@ubuntu-matt:~/Downloads$ zip -r test.epub META-INF/
  adding: META-INF/ (stored 0%)
  adding: META-INF/container.xml (deflated 33%)
mgarrish@ubuntu-matt:~/Downloads$ zip -r test.epub EPUB/
  adding: EPUB/ (stored 0%)
  adding: EPUB/images/ (stored 0%)
  adding: EPUB/images/img752a.jpg (deflated 0%)
  adding: EPUB/images/cover.png (deflated 5%)
  adding: EPUB/css/ (stored 0%)
  adding: EPUB/css/epub.css (deflated 37%)
  adding: EPUB/cover.xhtml (deflated 28%)
  adding: EPUB/package.opf (deflated 65%)
  adding: EPUB/lexicon/ (stored 0%)
  adding: EPUB/lexicon/en.pls (deflated 82%)
  adding: EPUB/toc.ncx (deflated 84%)
  adding: EPUB/georgia.xhtml (deflated 69%)
  adding: EPUB/nav.xhtml (deflated 76%)

Note that you need to use the -X option when adding the mimetype in addition to setting -0 for no compression, otherwise you'll get extra file attributes between the filename and identifier (which will make the epub invalid).

I made the mistake of clicking to upgrade my ubuntu install when I logged in, so I can't install anything for a while still, but if I find a program that provides compression options I'll post back later.

D'oh, copied the wrong output from the terminal for the mimetype (s/b .epub not .zip file extension).

I'm not sure how to make my MIMETYPE file the first file in my ZIP archive. The IDPF validator reports "Mimetype entry missing or not the first in archive" to an EPUB I'm generating. I tried 3 consecutive commands:
zip -X0 ../epubFilename.epub MIMETYPE
zip -rDX9 ../epubFilename.epub.epub META-INF -x "*.DS_Store" -x MIMETYPE
zip -rDX9 ../epubFilename.epub.epub OPS -x "*.DS_Store" -x MIMETYPE
I'm on Mac OSX. Anyone know a secret recipe to generate the EPUB from the command line? Thanks,Ted

The file name should be 'mimetype', not 'MIMETYPE'.

Else, on my Linux machines to get the complete book I use the following in the book directory:
zip -X0 book.epub mimetype
zip -X8Dur book.epub *

Except from the file name this is comparable to yours and works.
There are slightly other parameter combinations possible, especially for the second command.
Obviously, if something is already in the archive, it remains unchanged by the second command (if one does not change it meanwhile) and it does not try to archive the archive itself ;o)

Secondary menu