SharpDevelop Community

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

Whats wrong with this zip File-> GetError: Wrong Local header signature: 0x140033

Last post 02-20-2015 11:03 AM by Nahasapeemapetilon. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 02-13-2015 11:44 AM

    Whats wrong with this zip File-> GetError: Wrong Local header signature: 0x140033

    Hi 

    i create a test project u can find it :

    https://dl.dropboxusercontent.com/u/69535794/SharpLibZipTest.zip

    under SharpLibZipTest\bin\Debug is a zip file ("o.zip") 

    if i read the zip entries the first time i have no problems

    but if i modify the zip file with sharplib i get an exception if i read the zipentries again:  Wrong Local header signature: 0x140033

    with other zipfiles i have no problem with this code.

    i use sharplibzip 0.86.0.518

    here the code to read the zipentries:

       public void ReadZipEntries()

        {

          try

          {

            using (ZipInputStream tInput = new ZipInputStream(File.Open(mFileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)))

            {

              ZipEntry tEntry;

              while ((tEntry = tInput.GetNextEntry()) != null)

              {

                System.Console.WriteLine(tEntry.Name);

              }

            }

          }

          catch (Exception error)

          {

            System.Console.WriteLine("Error: {0}", error.Message.ToString());

          }

          System.Console.WriteLine("readEntrysDone");

        }

     

      public void RemoveFirstZipEntry()

        {

          ZipFile tZipFile = null;

          MemoryStream ms = new MemoryStream();

          mProjectStream.Position = 0;

          ICSharpCode.SharpZipLib.Core.StreamUtils.Copy(mProjectStream, ms, new byte[4096]);

          ms.Position = 0;

          tZipFile = new ZipFile(ms);

          tZipFile.IsStreamOwner = false;

          ZipEntry tZipEntry = null;

          if (tZipFile.Count > 0)

            tZipEntry = tZipFile[0];

          if (tZipEntry != null)

          {

            tZipFile.BeginUpdate();

            tZipFile.Delete(tZipEntry);

            tZipFile.CommitUpdate();

          }

          tZipFile.Close();

          ms.Position = 0;

          mProjectStream.Position = 0;

          mProjectStream.SetLength(0);

          ICSharpCode.SharpZipLib.Core.StreamUtils.Copy(ms, mProjectStream, new byte[4096]);

          mProjectStream.Flush();

        }

    the rest of the code u can find it in the SharpLibZipTest.zip

    thx

     

     

     

    Filed under: ,
  • 02-20-2015 11:03 AM In reply to

    Re: Whats wrong with this zip File-> GetError: Wrong Local header signature: 0x140033

    Hi,

    here is the whole test code :

    in test1 i try it with sharplibzip and test2() i try it with system.io.compression from .net 4.5 

    test2 works well with this zip and test1 throws an exception. The code of Test1 works with other zips without problems.

    here is the zip : https://dl.dropboxusercontent.com/u/69535794/o.zip this zipfile will not working.

    code:

     

    using System;

    using System.IO;

    using System.IO.Compression;

    using ICSharpCode.SharpZipLib.Zip;

    namespace SharpLibZipTest

    {

      class AlternativZipTest

      {

     

        private FileStream mProjectStream;

        private string mFileName;

     

        public AlternativZipTest(string pName)

        {

          mFileName = pName;

          FileInfo tFileInfo = new FileInfo(pName);

          if (tFileInfo.Exists)

            mProjectStream = tFileInfo.Open(FileMode.Open, FileAccess.ReadWrite, FileShare.Read);

        }

        public void RemoveFirstZipEntry()

        {

          MemoryStream ms = new MemoryStream();

          mProjectStream.Position = 0;

          ICSharpCode.SharpZipLib.Core.StreamUtils.Copy(mProjectStream, ms, new byte[4096]);

          ms.Position = 0;

          ZipArchive archive = new ZipArchive(ms, ZipArchiveMode.Update, true);

          ZipArchiveEntry entry = archive.Entries[0];

          entry.Delete();

          archive.Dispose();

          ms.Position = 0;

          mProjectStream.Position = 0;

          mProjectStream.SetLength(0);

          ICSharpCode.SharpZipLib.Core.StreamUtils.Copy(ms, mProjectStream, new byte[4096]);

          mProjectStream.Flush();

          System.Console.WriteLine("removeDone");

        }

     

        public void ReadZipEntries()

        {

          mProjectStream.Position = 0;

          using (ZipArchive archive = new ZipArchive(mProjectStream, ZipArchiveMode.Read, true))

          {

     

            foreach (ZipArchiveEntry entry in archive.Entries)

              System.Console.WriteLine(entry.FullName);

          }

          System.Console.WriteLine("readEntrysDone");

        }

     

        public void Close()

        {

          if (mProjectStream != null)

          {

            mProjectStream.Close();

            mProjectStream.Dispose();

          }

        }

      }

     

      class TestZipFile

      {

        private FileStream mProjectStream;

        private string mFileName;

     

        public TestZipFile(string pName)

        {

          mFileName = pName;

          FileInfo tFileInfo = new FileInfo(pName);

          if (tFileInfo.Exists)

            mProjectStream = tFileInfo.Open(FileMode.Open, FileAccess.ReadWrite, FileShare.Read);

        }   

     

        public void RemoveFirstZipEntry()

        {

          ZipFile tZipFile = null;

          MemoryStream ms = new MemoryStream();

          mProjectStream.Position = 0;

          ICSharpCode.SharpZipLib.Core.StreamUtils.Copy(mProjectStream, ms, new byte[4096]);

          ms.Position = 0;

          tZipFile = new ZipFile(ms);

          tZipFile.IsStreamOwner = false;

          ZipEntry tZipEntry = null;

          if (tZipFile.Count > 0)

            tZipEntry = tZipFile[0];

     

          if (tZipEntry != null)

          {

            tZipFile.BeginUpdate();

            tZipFile.Delete(tZipEntry);

            tZipFile.CommitUpdate();

          }

          tZipFile.Close();

          ms.Position = 0;      

          mProjectStream.Position = 0;

          mProjectStream.SetLength(0);

          ICSharpCode.SharpZipLib.Core.StreamUtils.Copy(ms, mProjectStream, new byte[4096]);

          mProjectStream.Flush();

        }

     

        public void ReadZipEntries()

        {

          try

          {

            using (ZipInputStream tInput = new ZipInputStream(File.Open(mFileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)))

            {

              ZipEntry tEntry = tInput.GetNextEntry() ;

              while (tEntry != null)

              {

                System.Console.WriteLine(tEntry.Name);

                try

                {

                  tEntry = tInput.GetNextEntry();              

                }

                catch (Exception error) 

                {

                  System.Console.WriteLine("Error: {0}", error.Message.ToString()); 

                  tEntry = null; 

                }

              }

            }

          }

          catch (Exception error)

          {

            System.Console.WriteLine("Error: {0}", error.Message.ToString());

          }

          System.Console.WriteLine("readEntrysDone");

        }

     

     

        public void Close()

        {

          if (mProjectStream != null)

          {

            mProjectStream.Close();

            mProjectStream.Dispose();

          }

        }

      }

     

     

     

     

      class Program

     

     {

     

        static void Test1()

        {

          File.Copy("o.zip", "test1.zip", true);

          TestZipFile tTest1 = new TestZipFile("test1.zip");

          tTest1.ReadZipEntries();

          tTest1.RemoveFirstZipEntry();

          tTest1.Close();

     

          TestZipFile tTest2 = new TestZipFile("test1.zip");

          tTest2.ReadZipEntries();       //----------------------------------------Exception------------------------------

          tTest2.Close();

          System.Console.WriteLine("test1Done");

          System.Console.ReadKey();

        }

     

        static void Test2()

        {

          File.Copy("o.zip", "test1.zip", true);

          AlternativZipTest tTest2 = new AlternativZipTest("test1.zip");

          tTest2.ReadZipEntries();

          tTest2.RemoveFirstZipEntry();

          tTest2.Close();

           tTest2 = new AlternativZipTest("test1.zip");

           tTest2.ReadZipEntries();

           System.Console.WriteLine("test2Done");

           System.Console.ReadKey();

        }

     

        static void Main(string[ args)

        {

          try

          {

           Test1();

     

          }

          catch { }

          try

          {

            Test2();

     

          }

          catch { }

     

        }

      }

    }

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.