FFMpegCore/FFMpegCore/FFMPEG/Pipes/StreamPipeDataWriter.cs
Максим Багрянцев 6bb03f6e14 Renamed IPipeSource to IpipeDataWriter
Former-commit-id: b7099f6709
2020-04-28 18:42:50 +03:00

46 lines
1.2 KiB
C#

using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace FFMpegCore.FFMPEG.Pipes
{
/// <summary>
/// Implementation of <see cref="IPipeDataWriter"/> used for stream redirection
/// </summary>
public class StreamPipeDataWriter : IPipeDataWriter
{
public System.IO.Stream Source { get; private set; }
public int BlockSize { get; set; } = 4096;
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 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 string GetFormat()
{
return "";
}
}
}