private static long CalculateGzipSize(byte[] bytes)
{
using (var memoryStream = new MemoryStream())
{
// the third parameter tells the GZIP stream to leave the base stream open so it doesn't
// dispose of it when it gets disposed. This is needed because we need to dispose the
// GZIP stream before it will write ANY of its data.
using (var gzipStream = new GZipStream(memoryStream, CompressionMode.Compress, true))
{
gzipStream.Write(bytes, 0, bytes.Length);
}
long compressedByteCount = memoryStream.Position;
memoryStream.Clear();
return compressedByteCount;
}
}