Example #1
0
 public static object UnzipObject(IZEntity z)
 {
     object result = null;
     using (MemoryStream zipStream = new MemoryStream(z.Data))
     {
         zipStream.Position = 0;
         using (GZipStream gZipStream = new GZipStream(zipStream, CompressionMode.Decompress))
         {
             byte[] buffer = new byte[z.Size];
             gZipStream.Read(buffer, 0, z.Size);
             using (MemoryStream ms = new MemoryStream(buffer))
             {
                 BinaryFormatter bf = new BinaryFormatter();
                 ms.Position = 0;
                 result = bf.Deserialize(ms);
             }
             if (result.GetType() != z.Type)
             {
                 throw new InvalidCastException("Decompressed stream does not correspond to source type");
             }
             gZipStream.Close();
         }
         zipStream.Close();
     }
     return result;
 }
Example #2
0
        public static object UnzipObject(IZEntity z)
        {
            object result = null;

            using (MemoryStream zipStream = new MemoryStream(z.Data))
            {
                zipStream.Position = 0;
                using (GZipStream gZipStream = new GZipStream(zipStream, CompressionMode.Decompress))
                {
                    byte[] buffer = new byte[z.Size];
                    gZipStream.Read(buffer, 0, z.Size);
                    using (MemoryStream ms = new MemoryStream(buffer))
                    {
                        BinaryFormatter bf = new BinaryFormatter();
                        ms.Position = 0;
                        result      = bf.Deserialize(ms);
                    }
                    if (result.GetType() != z.Type)
                    {
                        throw new InvalidCastException("Decompressed stream does not correspond to source type");
                    }
                    gZipStream.Close();
                }
                zipStream.Close();
            }
            return(result);
        }