From f132a3b731159caea291df50fae229a74e0d9ee1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=D0=B8=D0=BC=20=D0=91=D0=B0=D0=B3?= =?UTF-8?q?=D1=80=D1=8F=D0=BD=D1=86=D0=B5=D0=B2?= Date: Sat, 2 May 2020 13:13:22 +0300 Subject: [PATCH] StreamPipeDataWriter & StreamPipeDataReader using Stream.CopyTo --- .../FFMPEG/Pipes/StreamPipeDataReader.cs | 18 ++++----------- .../FFMPEG/Pipes/StreamPipeDataWriter.cs | 22 ++++--------------- 2 files changed, 8 insertions(+), 32 deletions(-) diff --git a/FFMpegCore/FFMPEG/Pipes/StreamPipeDataReader.cs b/FFMpegCore/FFMPEG/Pipes/StreamPipeDataReader.cs index 372d227..1c43dd2 100644 --- a/FFMpegCore/FFMPEG/Pipes/StreamPipeDataReader.cs +++ b/FFMpegCore/FFMPEG/Pipes/StreamPipeDataReader.cs @@ -16,21 +16,11 @@ public StreamPipeDataReader(System.IO.Stream destanationStream) DestanationStream = destanationStream; } - public void ReadData(System.IO.Stream stream) - { - int read; - var buffer = new byte[BlockSize]; - while ((read = stream.Read(buffer, 0, buffer.Length)) != 0) - DestanationStream.Write(buffer, 0, buffer.Length); - } + public void ReadData(System.IO.Stream stream) => + stream.CopyTo(DestanationStream, BlockSize); - public async Task ReadDataAsync(System.IO.Stream stream) - { - int read; - var buffer = new byte[BlockSize]; - while ((read = await stream.ReadAsync(buffer, 0, buffer.Length)) != 0) - await DestanationStream.WriteAsync(buffer, 0, buffer.Length); - } + public Task ReadDataAsync(System.IO.Stream stream) => + stream.CopyToAsync(DestanationStream, BlockSize); public string GetFormat() { diff --git a/FFMpegCore/FFMPEG/Pipes/StreamPipeDataWriter.cs b/FFMpegCore/FFMPEG/Pipes/StreamPipeDataWriter.cs index 8db19eb..e2b5120 100644 --- a/FFMpegCore/FFMPEG/Pipes/StreamPipeDataWriter.cs +++ b/FFMpegCore/FFMPEG/Pipes/StreamPipeDataWriter.cs @@ -19,25 +19,11 @@ public StreamPipeDataWriter(System.IO.Stream stream) Source = stream; } - public void WriteData(System.IO.Stream pipe) - { - var buffer = new byte[BlockSize]; - int read; - while ((read = Source.Read(buffer, 0, buffer.Length)) != 0) - { - pipe.Write(buffer, 0, read); - } - } + public void WriteData(System.IO.Stream pipe)=> + Source.CopyTo(pipe, BlockSize); - public async Task WriteDataAsync(System.IO.Stream pipe) - { - var buffer = new byte[BlockSize]; - int read; - while ((read = await Source.ReadAsync(buffer, 0, buffer.Length)) != 0) - { - await pipe.WriteAsync(buffer, 0, read); - } - } + public Task WriteDataAsync(System.IO.Stream pipe) => + Source.CopyToAsync(pipe, BlockSize); public string GetFormat() {