1

Closed

Utilities.FileFormats.Zip.ZipFile.AddFile Error When Adding 0 Byte File

description

I receive the following error when attempting add a file that is 0 bytes. I need the 0 byte file added to the Zip file. I do not get this error when using AddFolder Function.

WindowsBase : System.IO.FileFormatException
Archive file cannot be size 0.

at MS.Internal.IO.Zip.ZipArchive.OpenOnStream(Stream stream, FileMode mode, FileAccess access, Boolean streaming)
at System.IO.Packaging.ZipPackage..ctor(Stream s, FileMode mode, FileAccess access, Boolean streaming)
at System.IO.Packaging.Package.Open(Stream stream, FileMode packageMode, FileAccess packageAccess, Boolean streaming)
at System.IO.Packaging.Package.Open(Stream stream)
at Utilities.FileFormats.Zip.ZipFile.AddFile(String File) in C:\VS2010\Craig's Utility Library\UtilitiesFull\Utilities\FileFormats\Zip\ZipFile.cs:line 96
Closed Nov 29, 2011 at 3:04 PM by JaCraig

comments

lkannard wrote Nov 25, 2011 at 6:03 AM

Misinterpreted the error message. Could not open the newly created Zip file when it is 0 bytes.

To get it to not raise the error...
I Changed line 96 of ZipFile.cs from this...
        using (Package Package = ZipPackage.Open(ZipFileStream))
to this...
        using (Package Package = ZipPackage.Open(ZipFileStream, FileMode.OpenOrCreate))

lkannard wrote Nov 25, 2011 at 7:39 PM

When I compiled the library to use .NET 4.0 Full.

JaCraig wrote Nov 28, 2011 at 7:42 PM

Thanks for catching it. I'm adding the fix now and should have it uploaded in the repository later today.