/// <summary> /// Adapts a <see cref="Stream"/> into a <see cref="IPipeWriter"/>. /// </summary> /// <param name="stream"></param> /// <param name="pool"></param> /// <returns></returns> public static IPipeWriter AsPipelineWriter(this Stream stream, BufferPool pool) { var pipe = new Pipe(pool); pipe.CopyToAsync(stream); return(pipe); }
public IPipelineWriter CreateWriter(Stream stream) { if (!stream.CanWrite) { ThrowHelper.ThrowNotSupportedException(); } var pipe = new Pipe(_pool); pipe.CopyToAsync(stream).ContinueWith((task, state) => { var innerPipe = (Pipe)state; if (task.IsFaulted) { innerPipe.CompleteReader(task.Exception.InnerException); } else { innerPipe.CompleteReader(); } }, pipe, CancellationToken.None, TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default); return(pipe); }
/// <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 pipe = new Pipe(pool); pipe.CopyToAsync(stream).ContinueWith((task, state) => { var innerPipe = (Pipe)state; if (task.IsFaulted) { innerPipe.CompleteReader(task.Exception.InnerException); } else { innerPipe.CompleteReader(); } }, pipe, CancellationToken.None, TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default); return(pipe); }