SharpDevelop Community

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

Bug when password protecting a new zip file

Last post 02-16-2007 2:45 PM by David Balick. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 02-15-2007 10:27 PM

    Bug when password protecting a new zip file

    Using .85

    The following code creates a corrupt zip file. It works fine if the line setting the password is removed.

        public static void CreateZip(string zipFileName, string password, params string[] inputFiles)
        {
          using (ZipOutputStream zipOutputStream = new ZipOutputStream(File.Create(zipFileName)))
          {
            zipOutputStream.SetLevel(9); // 0 - store only to 9 - means best compression

             // comment out the following line to make the code work
            if (password != null) zipOutputStream.Password = password;

            byte[] buffer = new byte[4096];
            foreach (string file in inputFiles) {
                       
                        ZipEntry entry = new ZipEntry(Path.GetFileName(file));
                        entry.DateTime = DateTime.Now;
                        zipOutputStream.PutNextEntry(entry);
                        using ( FileStream fs = File.OpenRead(file) ) {
           
                            int sourceBytes;
                            do {
                                sourceBytes = fs.Read(buffer, 0, buffer.Length);
                                zipOutputStream.Write(buffer, 0, sourceBytes);
                                } while (sourceBytes > 0);
                     }
            }
       }
      

    Thanks. 

  • 02-16-2007 2:45 PM In reply to

    Re: Bug when password protecting a new zip file

    Actually, this is fixed in .85.1. The build properties must be modified: Uncheck "Check for arithmetic overflow/underflow".
     

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