Exemplo n.º 1
0
        public static IZEntity ZipObject(object o)
        {
            IZEntity result = new ZEntity();

            using (MemoryStream ms = new MemoryStream())
            {
                BinaryFormatter bf = new BinaryFormatter();
                bf.Serialize(ms, o);
                ms.Position = 0;
                result.Type = o.GetType();
                using (MemoryStream resultStream = new MemoryStream())
                {
                    using (GZipStream gZipStream = new GZipStream(resultStream, CompressionMode.Compress, true))
                    {
                        byte[] buffer = ms.ToArray();
                        gZipStream.Write(buffer, 0, buffer.Length);
                        gZipStream.Close();
                        result.Size = buffer.Length;
                    }
                    result.Data = resultStream.ToArray();
                }
                ms.Close();
            }
            return(result);
        }
Exemplo n.º 2
0
 public static IZEntity ZipObject(object o)
 {
     IZEntity result = new ZEntity();
     using (MemoryStream ms = new MemoryStream())
     {
         BinaryFormatter bf = new BinaryFormatter();
         bf.Serialize(ms, o);
         ms.Position = 0;
         result.Type = o.GetType();
         using (MemoryStream resultStream = new MemoryStream())
         {
             using (GZipStream gZipStream = new GZipStream(resultStream, CompressionMode.Compress, true))
             {
                 byte[] buffer = ms.ToArray();
                 gZipStream.Write(buffer, 0, buffer.Length);
                 gZipStream.Close();
                 result.Size = buffer.Length;
             }
             result.Data = resultStream.ToArray();
         }
         ms.Close();
     }
     return result;
 }