From 909f97d6014ab385e232d3b5112f4e524c623211 Mon Sep 17 00:00:00 2001 From: Jose Perez Rodriguez Date: Mon, 18 Jul 2016 11:19:34 -0700 Subject: [PATCH] Adding Apis to DeflateStream and GZipStream (dotnet/corefx#10071) Adding APM Apis to DeflateStream and GZipStream Commit migrated from https://github.com/dotnet/corefx/commit/fb26cd82d67c9bf065fc7370a40684be74c8d571 --- .../System.IO.Compression/ref/System.IO.Compression.cs | 12 ++++++++++++ .../System.IO.Compression/src/System.IO.Compression.csproj | 3 +++ .../src/System/IO/Compression/DeflateStream.cs | 14 ++++++++++++++ .../src/System/IO/Compression/GZipStream.cs | 14 ++++++++++++++ 4 files changed, 43 insertions(+) diff --git a/src/libraries/System.IO.Compression/ref/System.IO.Compression.cs b/src/libraries/System.IO.Compression/ref/System.IO.Compression.cs index 55bdbd6..a22495e 100644 --- a/src/libraries/System.IO.Compression/ref/System.IO.Compression.cs +++ b/src/libraries/System.IO.Compression/ref/System.IO.Compression.cs @@ -33,10 +33,16 @@ namespace System.IO.Compression public override long Position { get { return default(long); } set { } } protected override void Dispose(bool disposing) { } public override void Flush() { } + // Uncomment when Stream Begin/End Read is available + //public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback asyncCallback, object asyncState) { return default(IAsyncResult); } + //public override int EndRead(IAsyncResult asyncResult) { return default(int); } public override int Read(byte[] array, int offset, int count) { return default(int); } public override System.Threading.Tasks.Task ReadAsync(byte[] array, int offset, int count, System.Threading.CancellationToken cancellationToken) { return default(System.Threading.Tasks.Task); } public override long Seek(long offset, System.IO.SeekOrigin origin) { return default(long); } public override void SetLength(long value) { } + // Uncomment when Stream Begin/End Write is available + //public override IAsyncResult BeginWrite(byte[] array, int offset, int count, AsyncCallback asyncCallback, object asyncState) { return default(IAsyncResult); } + //public override void EndWrite(IAsyncResult asyncResult) { } public override void Write(byte[] array, int offset, int count) { } public override System.Threading.Tasks.Task WriteAsync(byte[] array, int offset, int count, System.Threading.CancellationToken cancellationToken) { return default(System.Threading.Tasks.Task); } } @@ -54,10 +60,16 @@ namespace System.IO.Compression public override long Position { get { return default(long); } set { } } protected override void Dispose(bool disposing) { } public override void Flush() { } + // Uncomment once Stream Begin/End Read are available. + //public override IAsyncResult BeginRead(byte[] array, int offset, int count, AsyncCallback asyncCallback, object asyncState) { return default(IAsyncResult); } + //public override int EndRead(IAsyncResult asyncResult) { return default(int); } public override int Read(byte[] array, int offset, int count) { return default(int); } public override System.Threading.Tasks.Task ReadAsync(byte[] array, int offset, int count, System.Threading.CancellationToken cancellationToken) { return default(System.Threading.Tasks.Task); } public override long Seek(long offset, System.IO.SeekOrigin origin) { return default(long); } public override void SetLength(long value) { } + // Uncomment once Stream Begin/End Write are available. + //public override IAsyncResult BeginWrite(byte[] array, int offset, int count, AsyncCallback asyncCallback, object asyncState) { return default(IAsyncResult); } + //public override void EndWrite(IAsyncResult asyncResult) { } public override void Write(byte[] array, int offset, int count) { } public override System.Threading.Tasks.Task WriteAsync(byte[] array, int offset, int count, System.Threading.CancellationToken cancellationToken) { return default(System.Threading.Tasks.Task); } } diff --git a/src/libraries/System.IO.Compression/src/System.IO.Compression.csproj b/src/libraries/System.IO.Compression/src/System.IO.Compression.csproj index 3797676..7cea21e 100644 --- a/src/libraries/System.IO.Compression/src/System.IO.Compression.csproj +++ b/src/libraries/System.IO.Compression/src/System.IO.Compression.csproj @@ -47,6 +47,9 @@ + + Common\System\Threading\Tasks\TaskToApm.cs + diff --git a/src/libraries/System.IO.Compression/src/System/IO/Compression/DeflateStream.cs b/src/libraries/System.IO.Compression/src/System/IO/Compression/DeflateStream.cs index 5c98395..aa38398 100644 --- a/src/libraries/System.IO.Compression/src/System/IO/Compression/DeflateStream.cs +++ b/src/libraries/System.IO.Compression/src/System/IO/Compression/DeflateStream.cs @@ -346,6 +346,13 @@ namespace System.IO.Compression throw new InvalidOperationException(SR.CannotWriteToDeflateStream); } + // Uncomment when Stream Begin/End Read is available + //public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback asyncCallback, object asyncState) => + // TaskToApm.Begin(ReadAsync(buffer, offset, count, CancellationToken.None), asyncCallback, asyncState); + + //public override int EndRead(IAsyncResult asyncResult) => + // TaskToApm.End(asyncResult); + public override Task ReadAsync(Byte[] array, int offset, int count, CancellationToken cancellationToken) { EnsureDecompressionMode(); @@ -588,6 +595,13 @@ namespace System.IO.Compression } } + // Uncomment when Stream Begin/End Write is available + //public override IAsyncResult BeginWrite(byte[] array, int offset, int count, AsyncCallback asyncCallback, object asyncState) => + // TaskToApm.Begin(WriteAsync(array, offset, count, CancellationToken.None), asyncCallback, asyncState); + + //public override void EndWrite(IAsyncResult asyncResult) => + // TaskToApm.End(asyncResult); + public override Task WriteAsync(Byte[] array, int offset, int count, CancellationToken cancellationToken) { EnsureCompressionMode(); diff --git a/src/libraries/System.IO.Compression/src/System/IO/Compression/GZipStream.cs b/src/libraries/System.IO.Compression/src/System/IO/Compression/GZipStream.cs index 8b906e1..9d93224 100644 --- a/src/libraries/System.IO.Compression/src/System/IO/Compression/GZipStream.cs +++ b/src/libraries/System.IO.Compression/src/System/IO/Compression/GZipStream.cs @@ -116,12 +116,26 @@ namespace System.IO.Compression return _deflateStream.ReadByte(); } + // Uncomment once Stream Begin/End Read are available. + //public override IAsyncResult BeginRead(byte[] array, int offset, int count, AsyncCallback asyncCallback, object asyncState) => + // TaskToApm.Begin(WriteAsync(array, offset, count, CancellationToken.None), asyncCallback, asyncState); + + //public override int EndRead(IAsyncResult asyncResult) => + // TaskToApm.End(asyncResult); + public override int Read(byte[] array, int offset, int count) { CheckDeflateStream(); return _deflateStream.Read(array, offset, count); } + // Uncomment once Stream Begin/End Write are available. + //public override IAsyncResult BeginWrite(byte[] array, int offset, int count, AsyncCallback asyncCallback, object asyncState) => + // TaskToApm.Begin(WriteAsync(array, offset, count, CancellationToken.None), asyncCallback, asyncState); + + //public override void EndWrite(IAsyncResult asyncResult) => + // TaskToApm.End(asyncResult); + public override void Write(byte[] array, int offset, int count) { CheckDeflateStream(); -- 2.7.4