Hi!
I'm trying to decompress my GunZip files from the web using an WPF app, I get no errors, but then, when I open the files, I see randomly inserted "z" and my files aren't complete!
Here is my code:
string file = sr.ReadLine().Replace(".gz", "");
SetInfo(Path.GetFileName(file));
int size = Convert.ToInt32(sr.ReadLine());
string inp = sr.ReadLine();
int insize = Convert.ToInt32(inp);
int pergo = insize;
while (pergo > 256)
pergo /= 2;
Uri uri = new Uri("http://mywebsite.com/data/" + file + ".gz");
Stream stream = client.OpenRead(uri);
byte[] data = new byte[size];
stream.Read(data, 0, data.Length);
MemoryStream ms = new MemoryStream(data);
ms.Seek(0, SeekOrigin.Begin);
GZipStream gzipstream = new GZipStream(ms, CompressionMode.Decompress);
string path = installPath + file;
FileStream fstream = File.Create(path);
while (insize > 0)
{
if (pergo > insize)
pergo = insize;
byte[] decompressed = new byte[pergo];
gzipstream.Read(decompressed, 0, pergo);
fstream.Write(decompressed, 0, decompressed.Length);
insize -= pergo;
}
gzipstream.Close();
gzipstream.Dispose();
fstream.Close();
fstream.Dispose();
stream.Close();
stream.Dispose();
My files aren't corrupted, I can still open them with IZark, and they work. (The files on the server not the downloaded ones)
Please tell what I'm doing wrong??