Reading a memorystream
Posted
by
user1842828
on Stack Overflow
See other posts from Stack Overflow
or by user1842828
Published on 2012-12-18T17:01:58Z
Indexed on
2012/12/18
17:03 UTC
Read the original article
Hit count: 198
Using several examples here on StackOverflow I thought the following code would decompress a gzip file then read the memory-stream and write it's content to the console. No errors occur but I get no output.
public static 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))
{
MemoryStream memStream = new MemoryStream();
memStream.SetLength(decompressedFileStream.Length);
decompressedFileStream.Read(memStream.GetBuffer(), 0, (int)decompressedFileStream.Length);
memStream.Position = 0;
var sr = new StreamReader(memStream);
var myStr = sr.ReadToEnd();
Console.WriteLine("Stream Output: " + myStr);
}
}
}
}
© Stack Overflow or respective owner