public void Write(byte[] data) { postedData = data; using (var stream = WebRequest.GetRequestStream()) using (var countingStream = new CountingStream(stream, l => NumberOfBytesWrittenCompressed = l)) using (var cmp = new GZipStream(countingStream, CompressionMode.Compress)) using (var countingStream2 = new CountingStream(cmp, l => NumberOfBytesWrittenUncompressed = l)) { countingStream2.Write(data, 0, data.Length); cmp.Flush(); stream.Flush(); } }
public void Write(byte[] data) { postedData = data; if (EnvironmentUtils.RunningOnPosix) // mono must set ContentLength before GetRequestStream (unlike .net) { WebRequest.ContentLength = data.Length; } using (var stream = WebRequest.GetRequestStream()) using (var countingStream = new CountingStream(stream, l => NumberOfBytesWrittenCompressed = l)) using (var cmp = new GZipStream(countingStream, CompressionMode.Compress)) using (var countingStream2 = new CountingStream(cmp, l => NumberOfBytesWrittenUncompressed = l)) { countingStream2.Write(data, 0, data.Length); cmp.Flush(); stream.Flush(); } }