Пример #1
0
 public static byte[] Decompress(byte[] compBytes)
 {
     using (MemoryStream compressed = new MemoryStream(compBytes))
     {
         using (GZipStream stream = new GZipStream(compressed, CompressionMode.Decompress, true))
         {
             using (var bytearrayBuffer = new ByteArrayBufferPool())
             {
                 byte[] buffer = bytearrayBuffer.ByteArray;
                 using (var ms = new MemoryStreamPool())
                 {
                     int count = 0;
                     do
                     {
                         count = stream.Read(buffer, 0, buffer.Length);
                         if (count > 0)
                         {
                             ms.Stream.Write(buffer, 0, count);
                         }
                     }while (count > 0);
                     return(ms.Stream.ToArray());
                 }
             }
         }
     }
 }
Пример #2
0
 public static byte[] Serialise <T>(T t)
 {
     using (var memstream = new MemoryStreamPool())
     {
         using (var serialiser = new BsonBinaryWriter(memstream.Stream))
         {
             BsonSerializer.Serialize(serialiser, typeof(T), t);
             return(memstream.Stream.ToArray());
         }
     }
 }
Пример #3
0
 public static byte[] Compress(byte[] data)
 {
     using (var ms = new MemoryStreamPool())
     {
         using (var gz = new GZipStream(ms.Stream, CompressionMode.Compress, true))
         {
             gz.Write(data, 0, data.Length);
         }
         return(ms.Stream.ToArray());
     }
 }