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

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

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

            return(gzipstream.BeginWrite(array, 0, array.Length, asyncCallback));
        }
        public void AsyncWrite()
        {
            GZipStream cs = new GZipStream(new MemoryStream(), CompressionMode.Compress);

            message = "AsyncWrite";
            reset.Reset();
            IAsyncResult r = cs.BeginWrite(new byte[0], 0, 0, 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 ();
        }
Ejemplo n.º 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);
            }
        }