Quantcast
Channel: SharpDevelop Community
Viewing all articles
Browse latest Browse all 1764

Use ZipFile to decompress a largefile throw wrong local header

$
0
0

I had a large zip file (the filesize>4GB),when use zipFile class to extract a file ,the code throw a exception "wrong local header"

 using (ZipFile zf = new ZipFile(path))

                {

                    foreach (ZipEntry ze in zf)

                    {

                        if (ze.IsFile)

                        {

                            MemoryStream ms = new MemoryStream();

                            using (Stream zis = zf.GetInputStream(ze.ZipFileIndex))

                            {

                                int size = 2048;

                                byte[ data = new byte[size];

                                while (true)

                                {

                                    size = zis.Read(data, 0, data.Length);

                                    if (size > 0)

                                    {

                                      ms.Write(data, 0, size);

                                        if (ms.Length > ze.Size)

                                            break;

                                    }

                                    else

                                    {

                                        break;

                                    }

                                }

                            }

above code work error, but when i use ZipInputStream to extract a file ,it work fine.

  ZipEntry theEntry;

            int size;

            using (ZipInputStream s = new ZipInputStream(File.OpenRead(path)))

            {

                while ((theEntry = s.GetNextEntry()) != null)

                {

                    if(theEntry.IsFile)

                    {

                        MemoryStream ms = new MemoryStream();

                        byte[ data = new byte[20480];

                        while (true)

                        {

                            size = s.Read(data, 0, data.Length);

                            if (size > 0)

                            {

                                ms.Write(data, 0, size);

                            }

                            else

                            {

                                break;

                            }

                        }

                        ms.Seek(0, SeekOrigin.Begin);

                        break;

                    }

                }

            }

 

is there a solution to fix this ,i want to use zipfile class feature?the dll version is 0.86.0.518;

thanks.


Viewing all articles
Browse latest Browse all 1764

Trending Articles