/// <summary>Begins an asynchronous write operation.</summary> /// <returns>An <see cref="T:System.IAsyncResult" /> object that represents the asynchronous write, which could still be pending.</returns> /// <param name="array">The buffer to write data from.</param> /// <param name="offset">The byte offset in <paramref name="buffer" /> to begin writing from.</param> /// <param name="count">The maximum number of bytes to write.</param> /// <param name="asyncCallback">An optional asynchronous callback, to be called when the write is complete.</param> /// <param name="asyncState">A user-provided object that distinguishes this particular asynchronous write request from other requests.</param> /// <exception cref="T:System.IO.IOException">An asynchronous write past the end of the stream was attempted, or a disk error occurred.</exception> /// <exception cref="T:System.ArgumentException">One or more of the arguments is invalid.</exception> /// <exception cref="T:System.ObjectDisposedException">Methods were called after the stream was closed.</exception> /// <exception cref="T:System.NotSupportedException">The current <see cref="T:System.IO.Compression.DeflateStream" /> implementation does not support the write operation.</exception> /// <exception cref="T:System.InvalidOperationException">The write operation cannot be performed because the stream is closed.</exception> public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback cback, object state) { if (this.disposed) { throw new ObjectDisposedException(base.GetType().FullName); } if (!this.CanWrite) { throw new InvalidOperationException("This stream does not support writing"); } if (buffer == null) { throw new ArgumentNullException("buffer"); } if (count < 0) { throw new ArgumentOutOfRangeException("count", "Must be >= 0"); } if (offset < 0) { throw new ArgumentOutOfRangeException("offset", "Must be >= 0"); } if (count + offset > buffer.Length) { throw new ArgumentException("Buffer too small. count/offset wrong."); } DeflateStream.WriteMethod writeMethod = new DeflateStream.WriteMethod(this.WriteInternal); return(writeMethod.BeginInvoke(buffer, offset, count, cback, state)); }
/// <summary>Ends an asynchronous write operation.</summary> /// <param name="asyncResult">A reference to the outstanding asynchronous I/O request.</param> /// <exception cref="T:System.ArgumentNullException"> /// <paramref name="asyncResult" /> is null.</exception> /// <exception cref="T:System.ArgumentException"> /// <paramref name="asyncResult" /> did not originate from a <see cref="M:System.IO.Compression.DeflateStream.BeginWrite(System.Byte[],System.Int32,System.Int32,System.AsyncCallback,System.Object)" /> method on the current stream.</exception> /// <exception cref="T:System.Exception">An exception was thrown during a call to <see cref="M:System.Threading.WaitHandle.WaitOne" />.</exception> /// <exception cref="T:System.InvalidOperationException">The stream is null.</exception> /// <exception cref="T:System.InvalidOperationException">The end write call is invalid.</exception> public override void EndWrite(IAsyncResult async_result) { if (async_result == null) { throw new ArgumentNullException("async_result"); } AsyncResult asyncResult = async_result as AsyncResult; if (asyncResult == null) { throw new ArgumentException("Invalid IAsyncResult", "async_result"); } DeflateStream.WriteMethod writeMethod = asyncResult.AsyncDelegate as DeflateStream.WriteMethod; if (writeMethod == null) { throw new ArgumentException("Invalid IAsyncResult", "async_result"); } writeMethod.EndInvoke(async_result); }