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() {