I have the error while decompressing
"The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or a non-white space character among the padding characters."
It compresses fine but doesn't decompress. I've looked at many other examples that have the same problem, and I feel like I'm following what's said but still am getting nothing when I decompress. Here's the compression and decompression methods:
public static string CompressData(string data)
{
byte[] bffr = Encoding.UTF8.GetBytes(data);
var mStream = new MemoryStream();
using (var gZipStream = new GZipStream(mStream, CompressionMode.Compress, true))
{
gZipStream.Write(bffr, 0, bffr.Length);
}
mStream.Position = 0;
var compressedData = new byte[mStream.Length];
mStream.Read(compressedData, 0, compressedData.Length);
var gZipBuffer = new byte[compressedData.Length + 4];
Buffer.BlockCopy(compressedData, 0, gZipBuffer, 4, compressedData.Length);
Buffer.BlockCopy(BitConverter.GetBytes(bffer.Length), 0, gZipBuffer, 0, 4);
return Convert.ToBase64String(gZipBuffer);
}
public static string DecompressData(string compressedData)
{
byte[] gZipBffr = Convert.FromBase64String(compressedData);
using (var mStream = new MemoryStream())
{
int dataLength = BitConverter.ToInt32(gZipBffr , 0);
mStream.Write(gZipBffr , 4, gZipBffr .Length - 4);
var buffer = new byte[dataLength];
mStream.Position = 0;
using (var gZipStream = new GZipStream(mStream, CompressionMode.Decompress))
{
gZipStream.Read(buffer, 0, buffer.Length);
}
return Encoding.UTF8.GetString(buffer);
}
}
string s = CompressData(s2.Tostring());
where s2 is type XElement string pH = DecompressData(stream2)); where stream2 is type string .. in the database it is stored in nvarchar type column here while compressing am removing the root tags .
for the first time the xml is like peet 3/24/2012 Percent 33.3 10 for next time another student data is added to the existing xml, here everytime while compressing we have to remove the parent tag.
<student>
<data>
<name>peet</name>
<date>3/24/2012</date>
<field>Percent</field>
<new>33.3</new>
<old>10</old>
</data>
<data>
<name>raaz</name>
<date>3/24/2011</date>
<field></field>
<new>33.3</new>
<old>10</old>
</data>
<data>
<name>arya</name>
<date>3/24/2010</date>
<field></field>
<new>33.3</new>
<old>10</old>
</data>
</student>