Ejemplo n.º 1
0
 /// <summary>Begins an asynchronous read operation.</summary>
 /// <returns>An <see cref="T:System.IAsyncResult" /> object that represents the asynchronous read, which could still be pending.</returns>
 /// <param name="array">The byte array to read the data into.</param>
 /// <param name="offset">The byte offset in <paramref name="array" /> at which to begin writing data read from the stream.</param>
 /// <param name="count">The maximum number of bytes to read.</param>
 /// <param name="asyncCallback">An optional asynchronous callback, to be called when the read is complete.</param>
 /// <param name="asyncState">A user-provided object that distinguishes this particular asynchronous read request from other requests.</param>
 /// <exception cref="T:System.IO.IOException">An asynchronous read 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 read operation.</exception>
 /// <exception cref="T:System.InvalidOperationException">This call cannot be completed. </exception>
 public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback cback, object state)
 {
     if (this.disposed)
     {
         throw new ObjectDisposedException(base.GetType().FullName);
     }
     if (!this.CanRead)
     {
         throw new NotSupportedException("This stream does not support reading");
     }
     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.ReadMethod readMethod = new DeflateStream.ReadMethod(this.ReadInternal);
     return(readMethod.BeginInvoke(buffer, offset, count, cback, state));
 }
Ejemplo n.º 2
0
        /// <summary>Waits for the pending asynchronous read to complete.</summary>
        /// <returns>The number of bytes read from the stream, between zero (0) and the number of bytes you requested. <see cref="T:System.IO.Compression.DeflateStream" /> returns zero (0) only at the end of the stream; otherwise, it blocks until at least one byte is available.</returns>
        /// <param name="asyncResult">The reference to the pending asynchronous request to finish.</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.BeginRead(System.Byte[],System.Int32,System.Int32,System.AsyncCallback,System.Object)" /> method on the current stream.</exception>
        /// <exception cref="T:System.SystemException">An exception was thrown during a call to <see cref="M:System.Threading.WaitHandle.WaitOne" />.</exception>
        /// <exception cref="T:System.InvalidOperationException">The end call is invalid because asynchronous read operations for this stream are not yet complete.</exception>
        /// <exception cref="T:System.InvalidOperationException">The stream is null.</exception>
        public override int EndRead(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.ReadMethod readMethod = asyncResult.AsyncDelegate as DeflateStream.ReadMethod;
            if (readMethod == null)
            {
                throw new ArgumentException("Invalid IAsyncResult", "async_result");
            }
            return(readMethod.EndInvoke(async_result));
        }