Reputation: 699
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.
Upvotes: 2
Views: 2439
Reputation: 111369
You seem to be reading and writing the same memory stream. I don't think that's possible; you should use two different streams: one from which you read, and another into which you write:
using (gzipStream = new GZipStream(writeStream,CompressionLevel.Fastest))
{
readStream.CopyTo(gzipStream);
}
Upvotes: 1