S
stewart
I'm getting the following error when trying to decompress a GZip
encoded string. Below is a simplified version of the code which you
can run.
// Define a string "test" which we are going to compress
then decompress
byte[] b = ASCIIEncoding.UTF8.GetBytes("test");
// Read in b and compress it to string s
MemoryStream ms = new MemoryStream();
GZipStream gz = new GZipStream
(ms ,CompressionMode.Compress);
gz.Write(b, 0, b.Length);
ms.Position = 0;
StreamReader sr = new StreamReader(ms);
string s = sr.ReadToEnd();
gz.Close();
// Take compressed string s and extract it to byte array
b2
byte[] b2 = new byte[4096];
ms = new MemoryStream(ASCIIEncoding.UTF8.GetBytes(s));
gz = new GZipStream(ms, CompressionMode.Decompress);
gz.Read(b2, 0, b2.Length);
The execeptio message given is "The magic number in GZip header is not
correct. Make sure you are passing in a GZip stream.".
Any thoughts?
encoded string. Below is a simplified version of the code which you
can run.
// Define a string "test" which we are going to compress
then decompress
byte[] b = ASCIIEncoding.UTF8.GetBytes("test");
// Read in b and compress it to string s
MemoryStream ms = new MemoryStream();
GZipStream gz = new GZipStream
(ms ,CompressionMode.Compress);
gz.Write(b, 0, b.Length);
ms.Position = 0;
StreamReader sr = new StreamReader(ms);
string s = sr.ReadToEnd();
gz.Close();
// Take compressed string s and extract it to byte array
b2
byte[] b2 = new byte[4096];
ms = new MemoryStream(ASCIIEncoding.UTF8.GetBytes(s));
gz = new GZipStream(ms, CompressionMode.Decompress);
gz.Read(b2, 0, b2.Length);
The execeptio message given is "The magic number in GZip header is not
correct. Make sure you are passing in a GZip stream.".
Any thoughts?