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