SharpDevelop Community

Get your problems solved!
Welcome to SharpDevelop Community Sign in | Join | Help
in Search

SharpZipLib - Invalid ZIP file header

Last post 06-17-2009 11:45 AM by Damian. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 01-26-2009 10:49 PM

    SharpZipLib - Invalid ZIP file header

    Hello.
    I try to create a ZIP file via SharpZipLib. I program with VisualWorks Smalltalk, using proxy classes connecting to the SharpZipLib DLL.
    Whenever I create a ZIP file via SharpZipLib the file header looks like:

     0: 50 4B 03 04 2D 00 00 00  08 00 0E 4A 37 3A 00 00  PK..-......J7:..
    10: 00 00 FF FF FF FF FF FF  FF FF 09 00 14 00 65 6E  ..ÿÿÿÿÿÿÿÿ....en
    20: 74 72 79 2E 74 78 74 01  00 10 00 00 00 00 00 00  try.txt.........
    30: ... 

    In the specification of the ZIP format is defined: compressed size from byte 19 to 22. uncompressed size from byte 23 to 26.
    But SharpZipLib creates (19-22) FF FF FF FF (23-26) FF FF FF FF, what defines a file size of 4294967295 bytes.

    My test file has a size of 17 bytes. So the result must be 
       (19-22) 11 00 00 00 (23-26) 11 00 00 00
    This represents a file size of 17 bytes in little endian.

    My examples are written in Smalltalk. But you can relate the Smalltalk classes and methods easily with the C# correspondent by name.
    All my example produce the upper, wrong file header.

    Example 1
    | stream zipOut entry fs br bw |

    stream := DotNET.System.IO.File Create: 'c:\temp\test.zip'.
    zipOut := ZipOutputStream New: stream.
    zipOut SetLevel: 9.
    entry := ZipEntry New: 'entry.txt'.
    zipOut PutNextEntry: entry.

    fs := DotNET.System.IO.File OpenRead: 'c:\temp\test.log'.
    br := DotNET.System.IO.BinaryReader New: fs.
    bw := DotNET.System.IO.BinaryWriter New: stream.
    bw Write: (br ReadBytes: fs Length).

    fs Close.
    zipOut Finish.
    zipOut Close.

    Example 2:
    | aStream zipOutputStream buffer entry writeStream |

    aStream := 'c:\temp\test.log' asFilename readStream.
    writeStream := FileStream New: 'c:\temp\test.zip' with: 1.
    [zipOutputStream := ZipOutputStream New: writeStream.
    zipOutputStream SetLevel: 9.
    buffer := ByteArray new: 4096.
    entry := ZipEntry New: 'entry.txt'.
    zipOutputStream PutNextEntry: entry.

    [aStream atEnd]
       whileFalse:
          [zipOutputStream Write: buffer with: 0 with: (aStream next: buffer size)].
          zipOutputStream Finish.
          zipOutputStream Close]
       ensure:
       [writeStream Close.
       aStream close]

    Example 3:
    | buffer zipEntry fileStream readBytes |

    zipStream := ZipOutputStream New: (DotNET.System.IO.File Create: 'c:\temp\test.zip').
    zipStream SetLevel: 9.

    buffer := ByteArray new: 4096.
    fileStream := DotNET.System.IO.File OpenRead: 'c:\temp\test.log'.
    zipEntry := ZipEntry New: 'entry.txt'.
    zipStream PutNextEntry: zipEntry.

    readBytes := 1.
    [readBytes > 0]
       whileTrue:
          [readBytes := fileStream Read: buffer with: 0 with: buffer size.
          zipStream Write: buffer with: 0 with: readBytes].
    fileStream Close.

    zipStream Finish.
    zipStream Close.

    Does anyone know what cause this error? Is there a Bug in SharpZipLib? Or did I forget a method call to create the correct file header?

    Thank you for your help.
    Tom

  • 06-16-2009 9:55 PM In reply to

    • Damian
    • Not Ranked
    • Joined on 06-16-2009
    • Poland
    • Posts 2

    Re: SharpZipLib - Invalid ZIP file header

    Hello,

    I am facing the same problem as reported by you.

    Have you found solution for this issue?, Please share:)

    Greetings,

    Damian

  • 06-17-2009 2:49 AM In reply to

    Re: SharpZipLib - Invalid ZIP file header

    Hi

    FFFFFFFF is minus one. First thing I would do is to ensure you are using traditional Winzip format. See, the new version of SharpZip caters for large files (over 2GB). The standard zip format does not handle this. There is an extension to the format called "Zip64" which handles 64 bit sizes, unsurprisingly.  SharpZip defaults to this if you do not tell it otherwise and it does not know how big the file is going to be.

    Switch it off as follows (using Tom's 3rd example - so that's what the famous SmallTalk looks like. Thanks for sharing!)

    zipStream := ZipOutputStream New: (DotNET.System.IO.File Create: 'c:\temp\test.zip').
    zipStream SetLevel: 9.
    zipStream UseZip64: UseZip64.Off   // or something to that effect

    Let us know if that helps

    Dave

     

  • 06-17-2009 11:45 AM In reply to

    • Damian
    • Not Ranked
    • Joined on 06-16-2009
    • Poland
    • Posts 2

    Re: SharpZipLib - Invalid ZIP file header

    Hello,

    Thanks for the answer. I've already found workaround for this problem.

    When CRC is calculated and putted into zip entry, one will find FF FF FF FF value as compresed size, when not putting forced CRC compresed size is ok. When FF value is set, there might be problems with old decompresors (like winrar 3.40), in new versions is ok, windows built in uncompressing is handling this ok as well.

    Greetings,

    Damian

Page 1 of 1 (4 items)
Powered by Community Server (Commercial Edition), by Telligent Systems
Don't contact us via this (fleischfalle@alphasierrapapa.com) email address.