public IPipelineWriter CreateWriter(Stream stream)
        {
            if (!stream.CanWrite)
            {
                ThrowHelper.ThrowNotSupportedException();
            }

            var input = new PipelineReaderWriter(_pool);

            input.CopyToAsync(stream).ContinueWith((task, state) =>
            {
                var innerInput = (PipelineReaderWriter)state;
                if (task.IsFaulted)
                {
                    innerInput.CompleteReader(task.Exception.InnerException);
                }
                else
                {
                    innerInput.CompleteReader();
                }
            },
            input, CancellationToken.None, TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default);

            return input;
        }
        public IPipelineWriter CreateWriter(Stream stream)
        {
            if (!stream.CanWrite)
            {
                ThrowHelper.ThrowNotSupportedException();
            }

            var input = new PipelineReaderWriter(_pool);

            input.CopyToAsync(stream).ContinueWith((task, state) =>
            {
                var innerInput = (PipelineReaderWriter)state;
                if (task.IsFaulted)
                {
                    innerInput.CompleteReader(task.Exception.InnerException);
                }
                else
                {
                    innerInput.CompleteReader();
                }
            },
                                                   input, CancellationToken.None, TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default);

            return(input);
        }
        /// <summary>
        /// Adapts a <see cref="Stream"/> into a <see cref="IPipelineWriter"/>.
        /// </summary>
        /// <param name="stream"></param>
        /// <param name="pool"></param>
        /// <returns></returns>
        public static IPipelineWriter AsPipelineWriter(this Stream stream, IBufferPool pool)
        {
            var writer = new PipelineReaderWriter(pool);
            writer.CopyToAsync(stream).ContinueWith((task, state) =>
            {
                var innerWriter = (PipelineReaderWriter)state;

                if (task.IsFaulted)
                {
                    innerWriter.CompleteReader(task.Exception.InnerException);
                }
                else
                {
                    innerWriter.CompleteReader();
                }
            }, 
            writer, CancellationToken.None, TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default);

            return writer;
        }
Example #4
0
        /// <summary>
        /// Adapts a <see cref="Stream"/> into a <see cref="IPipelineWriter"/>.
        /// </summary>
        /// <param name="stream"></param>
        /// <param name="pool"></param>
        /// <returns></returns>
        public static IPipelineWriter AsPipelineWriter(this Stream stream, IBufferPool pool)
        {
            var writer = new PipelineReaderWriter(pool);

            writer.CopyToAsync(stream).ContinueWith((task, state) =>
            {
                var innerWriter = (PipelineReaderWriter)state;

                if (task.IsFaulted)
                {
                    innerWriter.CompleteReader(task.Exception.InnerException);
                }
                else
                {
                    innerWriter.CompleteReader();
                }
            },
                                                    writer, CancellationToken.None, TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default);

            return(writer);
        }