1

Windows XP で VS 2008 SP1 を使用しています。

ICSharpCode.SharpZipLib.dll を古い 0.85.4.369 から新しい 0.86.0.518 に更新しました。

古い 0.85.4.369 で問題なく使用しています。

ファイルとフォルダーの両方を問題なく圧縮および解凍できました-まあ、今まで.

しかし、今では、ICSharpCode.SharpZipLib.dll も使用して生成した ZIP ファイルを読み取ると、"EOF In Header" エラーが発生します。

私のコード C# は同じで、変更はありません。

失敗: theEntry = z.GetNextEntry();

public static string LeerEtiquetaEmpaquetado(string zipFic)
{
    ZipInputStream z = null;
    DatosEmpaquetado datEmp;

    try
    {
        z = new ZipInputStream(File.OpenRead(zipFic));
        ZipEntry theEntry;

        do
        {
            theEntry = z.GetNextEntry();
            if (theEntry != null)
            {
                if (theEntry.Name.EndsWith("empaquetado.xml"))
                {
                    using (MemoryStream memWrt = new MemoryStream())
                    {
                        int size = 2048;
                        byte[] data = new byte[2048];
                        do
                        {
                            size = z.Read(data, 0, data.Length);
                            if ((size > 0))
                            {
                                memWrt.Write(data, 0, size);
                            }
                            else
                            {
                                break;
                            }
                        } while (true);

                        datEmp = LeerEmpaquetado(memWrt);
                        return datEmp.Etiqueta;
                    }
                    break;
                }
            }
            else
            {
                break;
            }
        } while (true);

        return null;
    }
    catch (Exception exc)
    {
        System.Diagnostics.Trace.WriteLine("Excepción: " + exc.Message);
        System.Diagnostics.Trace.WriteLine(exc.StackTrace);
        throw;
    }
    finally
    {
        if (z != null)
        {
            z.Close();
            z.Dispose();
        }
    }
}

ICSharpCode.SharpZipLib.dll ( 0.86.0.518 ) は、作成したばかりの ZIP を開くことができないようです。

非常に奇妙なことは次のとおりです。

  • 新しく作成されたファイルは、WinRAR で問題なく開きます。

  • 以前のバージョンの DLL で作成された ZIP ファイルは、新しい DLL で正常に開きます。

ZIP ファイルのコード:

public static void EmpaquetarProyecto(string dirOutput, string nombre, string dirDestino)
            {
                  string dirActual = Environment.CurrentDirectory;
                  Environment.CurrentDirectory = dirOutput;
                  string[] fileNames = Directory.GetFiles(".", "*.*", SearchOption.AllDirectories);
                  try
                  {
                        Crc32 objCrc32 = new Crc32();
                        ZipOutputStream strmZipOutputStream;
                        nombre = Path.Combine(dirDestino, nombre + ".zip");
                        strmZipOutputStream = new ZipOutputStream(File.Create(nombre));
                        strmZipOutputStream.SetLevel(6);

                        foreach (string aux in fileNames)
                        {
                             string strFile = aux;
                             if (strFile.StartsWith(".\\"))
                             {
                                   strFile = strFile.Substring(2);
                             }

                             FileStream strmFile = File.OpenRead(strFile);
                             byte[] abyBuffer = new byte[(Convert.ToInt32(strmFile.Length))];
                             strmFile.Read(abyBuffer, 0, abyBuffer.Length);
                             ZipEntry theEntry = new ZipEntry(strFile);
                             FileInfo fi = new FileInfo(strFile);
                             theEntry.DateTime = fi.LastWriteTime;
                             theEntry.Size = strmFile.Length;
                             strmFile.Close();
                             objCrc32.Reset();
                             objCrc32.Update(abyBuffer);
                             theEntry.Crc = objCrc32.Value;
                             strmZipOutputStream.PutNextEntry(theEntry);
                             strmZipOutputStream.Write(abyBuffer, 0, abyBuffer.Length);
                        }
                        strmZipOutputStream.Finish();
                        strmZipOutputStream.Close();
                  }
                  finally
                  {
                        Environment.CurrentDirectory = dirActual;
                  }
            }

おそらくエラーはCRCに関するものだと思います。

それについてのアイデアはありますか?私のコードに変更はありますか?

編集: CRC に関するコードを削除すると機能しますが、なぜ ??

4

0 に答える 0