none
System.IO.Compression.ZipFile issue RRS feed

  • Question

  • Hi mate,

    Recentlly I want to build an e-book i.e. epub generator, as we know the epub file actually is a zip file with multiple html pages insides. Generate the html file is easy, but the epub file I generate with System.IO.Compression.ZipFile can't open in Edge, it shows can't recognize the file, and the same files I generate by WinZip 19.0 and rename the extension to epub could successfully open by Edge.

    I zipped the 2 epub files and you can download here:

    two books zipped

    You will find 2 file with same content has different size, very strange, right??

    Wednesday, June 5, 2019 6:46 AM

Answers

  • >1st one is if I zip the mimetype file first

    I already pointed out that you compressed the mimetype file which is a mistake. The PKG-007 error tells me that most likely you didn't correct your code. 

    And a zip entry of "META-INF\container.xml" isn't the same as a "META-INF/container.xml" entry that is expected by epub checker. 

     



    Visual C++ MVP

    Friday, June 7, 2019 6:37 AM

All replies

  • I don't think either file is good epub...

    magic numbers:

    byte 0 PK0304 

    byte 30 mimetype ❌

    byte 38 application/epub+zip ❌

    Somehow Edge is more forgiving than most epub readers.

    Your WinZip version doesn't have the mimetype file at the first entry.

    Your System.IO version does have the mimetype file at the first entry but that entry has wrong content and CRC sum. The mimetype file should not be compressed. But then the entry is the same as your WinZip version so Edge is complaining about something else that I cannot find by staring at a hex editor.

    I suggest you to get epubcheck from github and see what error you get from it. 



    Visual C++ MVP

    Wednesday, June 5, 2019 6:27 PM
  • Hi Sheng,

    Thanks for support, I followed your way to use the epub checker and now I facing 3 issues:

    The 1st one is if I zip the mimetype file first and then zip the remaining files, the checker will reports: ERROR(PKG-007): C:/Users/wwy12/Documents/am2.epub/mimetype(-1,-1): Mimetype file should only contain the string 'application/epub+zip' and should not be compressed.  

    The 2nd on is if I zip the entire resource folder the checker will reports: ERROR(PKG-006): C:/Users/wwy12/Documents/am2.epub(-1,-1): Mimetype file entry is missing or is not the first file in the archive.

    Actually I don't think that is real question, because even if the book is not league by checker, the book still can open the either Edge or other portable device. The real question is, I hope I can generate the epub in code layer, i.e. using System.IO.Compression.ZipFile or something(the previous 2 files are dragged the files into WinZip manually), if I use System.IO.Compression.ZipFile to generate the file, the checker will report such like this:

    ERROR(PKG-007): C:/Users/wwy12/Documents/am.epub/mimetype(-1,-1): Mimetype file should only contain the string 'application/epub+zip' and should not be compressed.
    FATAL(RSC-002): C:/Users/wwy12/Documents/am.epub(-1,-1): Required META-INF/container.xml resource could not be found.
    ERROR(RSC-001): C:/Users/wwy12/Documents/am.epub(-1,-1): File 'META-INF/container.xml' could not be found.

    But as I know the file container.xml is existed in folder.

    Best.


    Thursday, June 6, 2019 8:50 AM
  • >1st one is if I zip the mimetype file first

    I already pointed out that you compressed the mimetype file which is a mistake. The PKG-007 error tells me that most likely you didn't correct your code. 

    And a zip entry of "META-INF\container.xml" isn't the same as a "META-INF/container.xml" entry that is expected by epub checker. 

     



    Visual C++ MVP

    Friday, June 7, 2019 6:37 AM
  • Hi Sheng,

    I finally created the epub with ZipArchive, no fatals, no errors, no warnings, completely prefect epub!!

    Thanks for support during these days.

    BR

    Thursday, June 13, 2019 9:24 AM