Search code examples
.netzipepubphp-ziparchive

How to create ePub with System.IO.Compression.ZipArchive?


I've written some code generating ePub archive using .NET 4.5 System.IO.Compression.ZipArchive. I need this to be part of a Portable Class Library (PCL), hence using a subset of .NET fx.

I have issue with the mimetype file containing the magic 'application/epub+zip'. Having read the specs, I add that file first with no compression.

Despite this care, the produced ePub archive isn't conforming to specs. Specs demand the content of the mimetype file should start at position 38. Mine starts at position 47.

There isn't any parameter on ZipArchive itself and ZipArchiveEntry can only be parametrized by compression mode only. I'm a bit confused since I thought Zip files came in one variety and I don't understand what influences this specific behaviour.

For reference, here are the first bits of a sample ePub (working that is):

enter image description here

and here is mine:

enter image description here


Solution

  • I did follow Nickolay's advice, I used DotNetZip to create an archive with only the mimetype file in it and use that file as a starting point for other epubs.

    This approach allows me to use ZipArchive and its async interface while respecting ePub's specs.