2

I have a gzipstream that is compressed and I want to write it to a file. Now the problem is that the Read is not supported on the gzipstream that is compressed. Below is my code where the gzipstream reads the stream from a memorystream and then I want to write it to a filestream.

using (var stream = new MemoryStream())
{
    using (FileStream file = new FileStream(@"c:\newest.xml.gz", 
        FileMode.Create, FileAccess.Write))
    {
        using (GZipStream gzs = new GZipStream(file, CompressionLevel.Fastest))
        {
            stream.CopyTo(gzs);
        }
    }  
} 

Any idea how I can create a filestream from a compressed gzipstream?

EDIT:

That was my bad, sorry to have waste your time. For future reference the code above should work, the problem was somewhere else.

4

1 回答 1

1

您似乎正在读取和写入相同的内存流。我认为这是不可能的;您应该使用两种不同的流:一个从中读取,另一个用于写入:

using (gzipStream = new GZipStream(writeStream,CompressionLevel.Fastest))
{
    readStream.CopyTo(gzipStream);
}
于 2013-10-11T10:00:46.570 回答