GZipStream解压缩不解压缩完整文件

时间:2016-06-21 10:45:42

标签: c# .net gzipstream

我正在尝试使用GZipStream解压缩.gz文件。它只会提取12kb的文件,但如果我使用winzip或7zip解压缩.gz文件,则提取的文件应为753kb。请参阅下面的代码我正在使用的任何关于我出错的地方?

public bool StartLibZipExtraction()
    {
        bool returnResult = false;

        try
        {
            DirectoryInfo directorySelected = new DirectoryInfo(m_ProjectPath);

            foreach (FileInfo fileToDecompress in directorySelected.GetFiles("*.gz"))
            {
                // check if this is the file to UNZIP
                if (fileToDecompress.Name.Equals(m_ZipFileName))
                {
                    returnResult = true;        // unzip successful
                    Agent.LogInfo("~~~ Unzipping file: " + fileToDecompress.ToString() + " ~~~");
                    Decompress(fileToDecompress);
                    break;
                }
            }
        }
        catch(Exception e)
        {
            Agent.LogInfo("*** StartLibZipExtraction() Error: " + e.Message + " ***");
            return false;
        }
        return returnResult;
    }


    public void Decompress(FileInfo fileToDecompress)
    {
        using (FileStream originalFileStream = fileToDecompress.OpenRead())
        {
            string currentFileName = fileToDecompress.FullName;
            string newFileName = currentFileName.Remove(currentFileName.Length - fileToDecompress.Extension.Length);


            using (FileStream decompressedFileStream = File.Create(newFileName))
            {
                using (GZipStream decompressionStream = new GZipStream(originalFileStream, CompressionMode.Decompress))
                {
                    decompressionStream.CopyTo(decompressedFileStream);
                    Agent.LogInfo(decompressionStream.ToString());
                    Agent.LogInfo("Decompressed: {0}" + fileToDecompress.Name);
                }
            }
        }
    }

0 个答案:

没有答案
相关问题