GZip标头中的幻数不正确减压给我错误

时间:2018-10-08 08:50:14

标签: c# .net compression

此解压缩方法给我一个错误,其中该行(numRead = Decompress.Read(buffer, 0, buffer.Length)) != 0给我一个错误,例如GZip标头中的幻数不正确。确保您正在传递GZip流。

我在这里用

发布了我的代码
public bool Decompress(string zipPathAndFile, string outputFolder, string password, bool deleteZipFile)
{
    FileInfo fi = new FileInfo(zipPathAndFile);
    try
    {
        // Get the stream of the source file.
        using (FileStream inFile = fi.OpenRead())
        {
            // Get original file extension, for example "doc" from report.doc.gz.
            string curFile = fi.Name;
            string origName = curFile.Remove(curFile.Length - fi.Extension.Length);

            //Create the decompressed file.
            using (FileStream outFile = File.Create(outputFolder.TrimEnd('\\') + '\\' + origName))
            {
                using (GZipStream Decompress = new GZipStream(inFile, CompressionMode.Decompress))
                {
                    //Copy the decompression stream into the output file.
                    byte[] buffer = new byte[4096];
                    int numRead;
                    while ((numRead = Decompress.Read(buffer, 0, buffer.Length)) != 0)
                    {
                        outFile.Write(buffer, 0, numRead);
                    }
                }
            }
        }
        return true;
    }
    catch (System.Exception exc)
    {
        ExceptionManagerBll.ErrHandler(exc, "ERR", 3, new StackTrace(new StackFrame(true)).GetFrame(0).GetFileLineNumber(), new StackTrace(new StackFrame(true)).GetFrame(0).GetMethod().DeclaringType.Name, new StackTrace(new StackFrame(true)).GetFrame(0).GetMethod().Name, "Error is Occured", true, false, "", "");
        return false;
    }
}

0 个答案:

没有答案