Example #1
0
        /// <summary>
        /// Extends BeginWrite so that when a state object is not needed, null does not need to be passed.
        /// <example>
        /// deflatestream.BeginWrite(array, offset, count, asyncCallback);
        /// </example>
        /// </summary>
        public static IAsyncResult BeginWrite(this DeflateStream deflatestream, Byte[] array, Int32 offset, Int32 count, AsyncCallback asyncCallback)
        {
            if (deflatestream == null)
            {
                throw new ArgumentNullException("deflatestream");
            }

            return(deflatestream.BeginWrite(array, offset, count, asyncCallback, null));
        }
Example #2
0
        /// <summary>
        /// Extends BeginWrite so that buffer offset of 0 and call to Array.Length are not needed.
        /// <example>
        /// deflatestream.BeginWrite(array, asyncCallback);
        /// </example>
        /// </summary>
        public static IAsyncResult BeginWrite(this DeflateStream deflatestream, Byte[] array, AsyncCallback asyncCallback)
        {
            if (deflatestream == null)
            {
                throw new ArgumentNullException("deflatestream");
            }

            if (array == null)
            {
                throw new ArgumentNullException("array");
            }

            return(deflatestream.BeginWrite(array, 0, array.Length, asyncCallback));
        }
Example #3
0
        public void AsyncWrite()
        {
            DeflateStream cs = new DeflateStream(new MemoryStream(), CompressionMode.Compress);

            message = "AsyncWrite";
            reset.Reset();
            IAsyncResult r = cs.BeginWrite(new byte[1], 0, 1, new AsyncCallback(WriteCallback), cs);

            Assert.IsNotNull(r, "IAsyncResult");
            if (!reset.WaitOne(timeout, true))
            {
                Assert.Ignore("Timeout");
            }
            Assert.IsNull(message, message);
// the Close is currently buggy in Mono
//			cs.Close ();
        }
Example #4
0
        /// <summary>
        /// Завершение чтения входного потока
        /// </summary>
        /// <param name="result">result - содержит manualEvent</param>
        protected virtual void EndReadCallBack(IAsyncResult result)
        {
            ManualResetEvent me = (ManualResetEvent)result.AsyncState;

            // Console.WriteLine("Read: Off={0} bytes={1}", offset, numBytes);

            // Читаем блок данных в буфер
            numBytes = fsStream.EndRead(result);
            // Теперь в buf находится numBytes байтов, их надо упаковать
            if (compressType == CompressType.Deflate)
            {
                result = dfStream.BeginWrite(buf, 0, numBytes, new AsyncCallback(EndWriteCallBack), me);
            }
            else
            {
                result = gzStream.BeginWrite(buf, 0, numBytes, new AsyncCallback(EndWriteCallBack), me);
            }
        }
Example #5
0
 /// <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 containing data to write to the current stream.</param>
 /// <param name="offset">The byte offset in <paramref name="array" /> at which to begin writing.</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.InvalidOperationException">The underlying stream is null. -or-The underlying stream is closed.</exception>
 public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback cback, object state)
 {
     return(deflateStream.BeginWrite(buffer, offset, count, cback, state));
 }