private void ReadAsBase64(XmlNode node, XmlNode dataNode)
{
// get a stream to the decoded Base64 text
Stream data = new MemoryStream(Convert.FromBase64String(node.InnerText), false);
// figure out what, if any, compression we're using. the compression determines
// if we need to wrap our data stream in a decompression stream
if (dataNode.Attributes["compression"] != null)
{
string compression = dataNode.Attributes["compression"].Value;
if (compression == "gzip")
{
data = new GZipStream(data, CompressionMode.Decompress, false);
}
else if (compression == "zlib")
{
data = new Ionic.Zlib.ZlibStream(data, Ionic.Zlib.CompressionMode.Decompress, false);
}
else
{
throw new InvalidOperationException("Unknown compression: " + compression);
}
}
// simply read in all the integers
using (data)
{
using (BinaryReader reader = new BinaryReader(data))
{
for (int i = 0; i < Data.Length; i++)
{
Data[i] = reader.ReadInt32();
}
}
}
}