StreamPipeDataWriter & StreamPipeDataReader using Stream.CopyTo

Former-commit-id: f132a3b731
This commit is contained in:
Максим Багрянцев 2020-05-02 13:13:22 +03:00
parent ed1284fc31
commit 9e0c15cb64
2 changed files with 8 additions and 32 deletions

View file

@ -16,21 +16,11 @@ public StreamPipeDataReader(System.IO.Stream destanationStream)
DestanationStream = destanationStream; DestanationStream = destanationStream;
} }
public void ReadData(System.IO.Stream stream) public void ReadData(System.IO.Stream stream) =>
{ stream.CopyTo(DestanationStream, BlockSize);
int read;
var buffer = new byte[BlockSize];
while ((read = stream.Read(buffer, 0, buffer.Length)) != 0)
DestanationStream.Write(buffer, 0, buffer.Length);
}
public async Task ReadDataAsync(System.IO.Stream stream) public Task ReadDataAsync(System.IO.Stream stream) =>
{ stream.CopyToAsync(DestanationStream, BlockSize);
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 string GetFormat() public string GetFormat()
{ {

View file

@ -19,25 +19,11 @@ public StreamPipeDataWriter(System.IO.Stream stream)
Source = stream; Source = stream;
} }
public void WriteData(System.IO.Stream pipe) public void WriteData(System.IO.Stream pipe)=>
{ Source.CopyTo(pipe, BlockSize);
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) public Task WriteDataAsync(System.IO.Stream pipe) =>
{ Source.CopyToAsync(pipe, BlockSize);
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() public string GetFormat()
{ {