public static byte[] CompressWithLength(byte[] input) { MemoryStream memoryStream = new MemoryStream(); GZipStream gZipStream = new GZipStream(memoryStream, CompressionMode.Compress, true); IOTools.BytesToStream(input, gZipStream); gZipStream.Close(); memoryStream.Position = 0L; MemoryStream memoryStream2 = new MemoryStream(); byte[] array = new byte[memoryStream.Length]; memoryStream.Read(array, 0, array.Length); byte[] array2 = new byte[array.Length + 4]; Buffer.BlockCopy(array, 0, array2, 4, array.Length); Buffer.BlockCopy(BitConverter.GetBytes(input.Length), 0, array2, 0, 4); return(array2); }
public static byte[] CompressWithLength(byte[] input) { MemoryStream memoryStream1 = new MemoryStream(); GZipStream gzipStream = new GZipStream((Stream)memoryStream1, CompressionMode.Compress, true); IOTools.BytesToStream(input, (Stream)gzipStream); gzipStream.Close(); memoryStream1.Position = 0L; MemoryStream memoryStream2 = new MemoryStream(); byte[] buffer = new byte[memoryStream1.Length]; memoryStream1.Read(buffer, 0, buffer.Length); byte[] numArray = new byte[buffer.Length + 4]; Buffer.BlockCopy((Array)buffer, 0, (Array)numArray, 4, buffer.Length); Buffer.BlockCopy((Array)BitConverter.GetBytes(input.Length), 0, (Array)numArray, 0, 4); return(numArray); }