![]() |
#1 |
Reader/Developer
![]() Posts: 6
Karma: 10
Join Date: Dec 2009
Device: Sony PRS-600
|
![]()
According to the ePub OCF spec, the ePub format should be zipped using the PK Zip compression method, as described in the PKware APPNOTE:
http://www.pkware.com/documents/casestudies/APPNOTE.TXT The short version of my question: I'm looking for an easy, cross-platform way to accomplish this in a conversion tool I'm writing. More specifically: I'm designing an ePub library (and tool) for Ruby to handle, manipulate, and create ePub files. Directory and file creation is easy enough, but Zipping them up into an ePub file gets tricky. Right now, I'm using the following (on OS X, should work in Linux, too): Code:
`zip -X0 Sample.epub mimetype` `zip -rX9 Sample.epub * -x mimetype` PK...........;oa .,............mi metypeapplicatio n/epub+zipPK... ......l.;...... ..........META-I NF/PK........%.. ;.f......4...... .META-INF/contai ner.xml That is, mimetype and 'application/epub+zip' occur at the right offsets, according to the spec. But no other Zip utility I've found will output this type of Zip file! Not in OS X ('compress') or Linux or Windows (Send to -> Archive). Trying rubyzip and zipruby didn't help. My files never turn out correct using these tools/libraries, and they don't pass epubcheck. Any suggestions on what library I should use to Zip up my archives? Last edited by acts_as_david; 12-31-2009 at 05:29 PM. Reason: fix code sections |
![]() |
![]() |
![]() |
#2 |
Guru
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 610
Karma: 4150
Join Date: Mar 2008
Device: Sony Reader PRS-T3, Kobo Libra H2O
|
The most common ZIP library is ZLib.
InfoZip is a command line utility that works on both Windows and Linux and produces the expected output. |
![]() |
![]() |
![]() |
#3 |
Reader/Developer
![]() Posts: 6
Karma: 10
Join Date: Dec 2009
Device: Sony PRS-600
|
Okay, thanks for the suggestions. I think I'll try Zlib first (it's part of the standard Ruby library) and maybe move onto InfoZip if that doesn't work.
One thing I'm not clear on is how many Zip specifications there are? I had thought that any Zip implementation would produce identical Zip files, but as I've said, rubyzip and zipruby didn't. How can you tell whether an implementation will churn out the right type of file? |
![]() |
![]() |
![]() |
#4 |
<Insert Wit Here>
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,017
Karma: 1275899
Join Date: Jan 2008
Location: Puget Sound
Device: Kindle Oasis, Kobo Forma
|
There is only one ZIP spec, but there are a lot of similar-sounding compression schemes that aren't ZIP (bzip, gzip which don't have an internal file structure, for example, and tend to need you to use the tar format underneath to archive/compress a folder).
One of the other problems you are looking at is that the mimetype needs to be stored rather than compressed in the ZIP archive as the first file. Not all zip libraries even support setting compression for individual files (versus the whole archive). compress doesn't create ZIP archives, which is a key distinction as well. |
![]() |
![]() |
![]() |
#5 |
frumious Bandersnatch
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 7,542
Karma: 19001583
Join Date: Jan 2008
Location: Spaniard in Sweden
Device: Cybook Orizon, Kobo Aura
|
|
![]() |
![]() |
![]() |
#6 | ||
Created Sigil, FlightCrew
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,982
Karma: 350515
Join Date: Feb 2008
Device: Kobo Clara HD
|
Quote:
It's used in Sigil, and I recommend it highly. Works perfectly across Windows, Linux, Mac OS X and the various BSD's. If your app will be GPL-compatible, feel free to take a look at the patched ZipArchive used in Sigil: it fixes a few bugs related to python generated ZIP files and improves BSD support. Quote:
You cannot use it (alone) to create a ZIP archive. Last edited by Valloric; 01-01-2010 at 10:36 AM. Reason: typo |
||
![]() |
![]() |
![]() |
#7 |
Banned
![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 475
Karma: 796
Join Date: Sep 2008
Location: Honolulu
Device: Nokia 770 (fbreader)
|
|
![]() |
![]() |
![]() |
#8 | ||
Reader/Developer
![]() Posts: 6
Karma: 10
Join Date: Dec 2009
Device: Sony PRS-600
|
Quote:
Quote:
|
||
![]() |
![]() |
![]() |
#9 |
frumious Bandersnatch
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 7,542
Karma: 19001583
Join Date: Jan 2008
Location: Spaniard in Sweden
Device: Cybook Orizon, Kobo Aura
|
No, it just eliminates the entries for the directories themselves. The files are still stored with their paths. As the man page says, the directory entries are useful when you want to store their permissions, but you don't need the permissions in an ePUB, so you don't need the directory entries.
|
![]() |
![]() |
![]() |
#10 |
Banned
![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 475
Karma: 796
Join Date: Sep 2008
Location: Honolulu
Device: Nokia 770 (fbreader)
|
I spent an hour or two yesterday trying to figure out how to store a set of files using zip so that the relative path would be correct, and so that it wouldn't store the full path.
-j definitely killed all the directory info; never could find a way to tell zip to store the path info starting from a given directory. Is there such a trick? I finally had to write a macro that would generate a batch file that would cd to the proper directory and run the zip commands from there. I'm doing this on a virtual machine of Win2k, although I generally use Linux; the world's greatest text editor requires Windows, sadly... m a r |
![]() |
![]() |
![]() |
#11 | ||
frumious Bandersnatch
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 7,542
Karma: 19001583
Join Date: Jan 2008
Location: Spaniard in Sweden
Device: Cybook Orizon, Kobo Aura
|
Quote:
Quote:
![]() |
||
![]() |
![]() |
![]() |
#12 |
Member
![]() Posts: 13
Karma: 64
Join Date: Nov 2009
Location: S. Ontario, Canada
Device: Jetbook, Sony PRS-505
|
I was playing around in VB trying to create epub files.
The only way I could get it to work was by having a base zip file with mimetype at the right offset and the uncompressed data. I then copied that file to the filename I wanted. I then had to change directory to the files I wanted to add so that pathnames were not included. Then add my files to the canned zipfile. This was the only reliable way I could get properly formated epubs. Since I was modifying already created epubs, I eventually decided it was easier to extract the html, modify it and then zip back to the original epub. Solves all the problems. |
![]() |
![]() |
![]() |
#13 | ||
Banned
![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 475
Karma: 796
Join Date: Sep 2008
Location: Honolulu
Device: Nokia 770 (fbreader)
|
@Slash5: me, too, basically!
Quote:
Quote:
m a r ps: Brain shreditor. ![]() |
||
![]() |
![]() |
![]() |
#14 | |
Reader/Developer
![]() Posts: 6
Karma: 10
Join Date: Dec 2009
Device: Sony PRS-600
|
Quote:
Also, running the zip command is working fine for me, re: relative file paths. In other words, running zip (etc., etc.) from within the directory I manually created gives me a proper ePub file. How are you guys running the zip command? |
|
![]() |
![]() |
![]() |
#15 |
Banned
![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 475
Karma: 796
Join Date: Sep 2008
Location: Honolulu
Device: Nokia 770 (fbreader)
|
I was running it as a macro, so it was being called from the current directory, or the root of the drive, which gave me the full path stored in the zip. Not good.
So I had to rewrite the macro as described above to start a new process in the appropriate directory. m a r |
![]() |
![]() |
![]() |
Tags |
cross-platform, epub, offset, ruby, zip |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
ePub Zip/Unzip AppleScript application for Mac OS X | pdurrant | ePub | 149 | 12-02-2024 12:51 PM |
Zip-Probleme EPUB | MichaelMBerlin | ePub | 4 | 08-27-2010 08:26 AM |
Help! My How do you chnage a ZIP to an Epub? | Greg Anos | ePub | 4 | 08-08-2010 07:07 PM |
citations in epub spec? | romnempire | ePub | 8 | 06-13-2010 04:43 AM |
Other formats than ePub or Zip? | Robotech_Master | Calibre | 4 | 05-28-2009 02:15 PM |