C# gzip powerpoint文件不工作

C# gzip powerpoint文件不工作,c#,gzip,C#,Gzip,我想知道是否有可能gzip一个powerpoint文件。我问这个问题的原因是因为我发现的所有文章都是gzip a.txt,并且想知道是否可以gzip a.pptx。。通过使用c#。。下面的代码是我正在使用的 static void Main() { try { string anyString = File.ReadAllText("presentation.pptx"); CompressStringToFile("new.gz", a

我想知道是否有可能gzip一个powerpoint文件。我问这个问题的原因是因为我发现的所有文章都是gzip a.txt,并且想知道是否可以gzip a.pptx。。通过使用c#。。下面的代码是我正在使用的

static void Main()
    {
    try
    {
        string anyString = File.ReadAllText("presentation.pptx");

        CompressStringToFile("new.gz", anyString);
    }
    catch
    {
        // Couldn't compress.
    }
    }

    public static void CompressStringToFile(string fileName, string value)
    {
    // A.
    // Write string to temporary file.
    string temp = Path.GetTempFileName();
    File.WriteAllText(temp, value);

    // B.
    // Read file into byte array buffer.
    byte[] b;
    using (FileStream f = new FileStream(temp, FileMode.Open))
    {
        b = new byte[f.Length];
        f.Read(b, 0, (int)f.Length);
    }


    using (FileStream f2 = new FileStream(fileName, FileMode.Create))
    using (GZipStream gz = new GZipStream(f2, CompressionMode.Compress, false))
    {
        gz.Write(b, 0, b.Length);
    }
    }
.pptx文件(也包括.docx和.xlsx)已压缩。如果将文件扩展名更改为.zip并打开文件,您将看到内容


因此,虽然您应该能够gzip这些文件中的一个,但不太可能看到大量的进一步压缩。

说我有一个1mb的文件,我要gzip它不会有太大的区别。但是说我想仍然gzip该文件,我怎么做呢?确定,而不是file.ReadAllText(.pptx不是文本文件)我认为您应该在.pptx文件上打开一个文件流。进入循环,使用fileStream.read()读取块并将这些块写入GZipStream。