Register Guidelines E-Books Search Today's Posts Mark Forums Read

Go Back   MobileRead Forums > E-Book Formats > ePub

Notices

Reply
 
Thread Tools Search this Thread
Old 09-10-2008, 11:17 AM   #1
wallcraft
reader
wallcraft ought to be getting tired of karma fortunes by now.wallcraft ought to be getting tired of karma fortunes by now.wallcraft ought to be getting tired of karma fortunes by now.wallcraft ought to be getting tired of karma fortunes by now.wallcraft ought to be getting tired of karma fortunes by now.wallcraft ought to be getting tired of karma fortunes by now.wallcraft ought to be getting tired of karma fortunes by now.wallcraft ought to be getting tired of karma fortunes by now.wallcraft ought to be getting tired of karma fortunes by now.wallcraft ought to be getting tired of karma fortunes by now.wallcraft ought to be getting tired of karma fortunes by now.
 
wallcraft's Avatar
 
Posts: 6,979
Karma: 5183568
Join Date: Mar 2006
Location: Mississippi, USA
Device: Kindle 3 and Fire
Explode and Implode an ePub?

The ePub container is just a ZIP file with standard compression, except that the file mimetype must be first and must not be compressed.

So, to "explode" an .epub file all you need is any command or utility that extracts files from a ZIP. To "implode" (is there a better term for this?) it back to a .epub isn't quite as easy. Salty-horse provides a Unix command line "implode" procedure here. Since it is using Info-ZIP, something similar should work for the Windows command line and on a Mac.

Is there a better 1-step, or GUI-based, method to do this?

Note that the contents of an ePub are fairly rigidly defined, and an explode/implode tool does nothing to check the validity of the contents (I guess the implode could check that the mimetype file exists and had the right contents, or make one if there is none). As in salty-horse's example, it would be most useful when something is wrong with an existing DRM-free ePub and you want to fix it.
wallcraft is offline   Reply With Quote
Old 09-10-2008, 04:40 PM   #2
Peter Sorotokin
speaking for myself
Peter Sorotokin knows what time it isPeter Sorotokin knows what time it isPeter Sorotokin knows what time it isPeter Sorotokin knows what time it isPeter Sorotokin knows what time it isPeter Sorotokin knows what time it isPeter Sorotokin knows what time it isPeter Sorotokin knows what time it isPeter Sorotokin knows what time it isPeter Sorotokin knows what time it isPeter Sorotokin knows what time it is
 
Posts: 139
Karma: 2166
Join Date: Feb 2008
Location: San Francisco Bay Area
Device: PRS-505
On Windows, just create a "compressed folder" (built-in functionality of Explorer) and add mimetype file as a first step before everything else. It figures out automatically that it is too small to compress, so it adds it as is. Then add everything else.

The same may be true for other GUI Zip utilities.
Peter Sorotokin is offline   Reply With Quote
Old 09-10-2008, 07:09 PM   #3
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 25,451
Karma: 4961459
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Do any epub reading systems actually insist on the mimetype file being first?
kovidgoyal is offline   Reply With Quote
Old 09-11-2008, 11:36 AM   #4
wallcraft
reader
wallcraft ought to be getting tired of karma fortunes by now.wallcraft ought to be getting tired of karma fortunes by now.wallcraft ought to be getting tired of karma fortunes by now.wallcraft ought to be getting tired of karma fortunes by now.wallcraft ought to be getting tired of karma fortunes by now.wallcraft ought to be getting tired of karma fortunes by now.wallcraft ought to be getting tired of karma fortunes by now.wallcraft ought to be getting tired of karma fortunes by now.wallcraft ought to be getting tired of karma fortunes by now.wallcraft ought to be getting tired of karma fortunes by now.wallcraft ought to be getting tired of karma fortunes by now.
 
wallcraft's Avatar
 
Posts: 6,979
Karma: 5183568
Join Date: Mar 2006
Location: Mississippi, USA
Device: Kindle 3 and Fire
Quote:
Originally Posted by kovidgoyal View Post
Do any epub reading systems actually insist on the mimetype file being first?
Probably not. In principle the Unix file command should be able to identify the file as an ePub if mimetype is first, but under Fedora 9 all I get is "Zip archive". Even FBReader (which looks inside .pdb files for the file type) just keys on the .epub filename extension.

For Linux, the following single command works:
Code:
zip -vur Author_Title.epub mimetype *
The "*" wildcard also includes mimetype but it still ends up 1st in the file and uncompressed. The "-u" does not seem necessary, but it is supposed to only overwrite existing files in the archive with newer versions.
wallcraft is offline   Reply With Quote
Old 09-12-2008, 09:34 AM   #5
salty-horse
Enthusiast
salty-horse got an A in P-Chem.salty-horse got an A in P-Chem.salty-horse got an A in P-Chem.salty-horse got an A in P-Chem.salty-horse got an A in P-Chem.salty-horse got an A in P-Chem.salty-horse got an A in P-Chem.salty-horse got an A in P-Chem.salty-horse got an A in P-Chem.salty-horse got an A in P-Chem.salty-horse got an A in P-Chem.
 
salty-horse's Avatar
 
Posts: 27
Karma: 6166
Join Date: Sep 2008
Device: Sony PRS-T1
Info-Zip actually checks if the "deflate" algorithm will reduce the file size. In the case of the mimetype file, it's too small for the algorithm to be efficient, so no compression is done.

It also removes duplicates from the file list (such as the case of "mimetype *"), and zips the files by order.

All of those form a very nice trick.

HOWEVER (and I just figured this out), this creates a non-standard epub file.

The specification states:

http://www.idpf.org/ocf/ocf1.0/download/ocf10.htm

Quote:
The [mimetype] file MUST be neither compressed nor encrypted and there MUST NOT be an extra field in its ZIP header.
By default, zip adds "extra file attributes". This prevent the text 'application/epub+zip' from being located in byte 38 in the epub file.

The original in my post used the -X flag on the mimetype. That flag strips away the headers, and is what required by the spec.

BTW, the commands were given to me by Hadrien Gardeur. I claim no credit.
salty-horse is offline   Reply With Quote
Old 09-12-2008, 09:47 AM   #6
salty-horse
Enthusiast
salty-horse got an A in P-Chem.salty-horse got an A in P-Chem.salty-horse got an A in P-Chem.salty-horse got an A in P-Chem.salty-horse got an A in P-Chem.salty-horse got an A in P-Chem.salty-horse got an A in P-Chem.salty-horse got an A in P-Chem.salty-horse got an A in P-Chem.salty-horse got an A in P-Chem.salty-horse got an A in P-Chem.
 
salty-horse's Avatar
 
Posts: 27
Karma: 6166
Join Date: Sep 2008
Device: Sony PRS-T1
Doh!

Code:
zip -Xvur Author_Title.epub mimetype *
Yay! The extended file attributes store things like Unix user and group id's. They're really meaningless when zipping and unzipping on different machines, so why not compress all files like this...
The zip command is verbose by default, and -u isn't needed for new files, so you can even make this shorter:

Code:
zip -Xr Author_Title.epub mimetype *
salty-horse is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
explode - plucker to html pruss Other formats 11 02-23-2013 10:55 PM
Can Calibre explode a MobiPocket .prc file and then reassemble it? cyberbaffled Calibre 1 06-15-2010 11:14 PM
epub, ePub, EPUB, warum blos ePub? flowoeB Lounge 5 11-27-2009 09:37 AM


All times are GMT -4. The time now is 06:02 AM.


MobileRead.com is a privately owned, operated and funded community.