feat: add system.io.pipeline support to pipe io
This commit is contained in:
parent
50a92291dc
commit
461a5b9066
3 changed files with 87 additions and 0 deletions
|
|
@ -2,6 +2,7 @@
|
|||
// SPDX-License-Identifier: EUPL-1.2
|
||||
|
||||
using System.Text;
|
||||
using System.IO.Pipelines;
|
||||
|
||||
using Geekeey.Process.Buffered;
|
||||
|
||||
|
|
@ -64,6 +65,23 @@ internal sealed class PipingTests
|
|||
await Assert.That(result.StandardOutput.Trim()).IsEqualTo("Hello World!");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task I_can_execute_a_command_and_pipe_the_stdin_from_a_pipe_reader()
|
||||
{
|
||||
var pipe = new Pipe();
|
||||
await pipe.Writer.WriteAsync("Hello World!"u8.ToArray());
|
||||
await pipe.Writer.CompleteAsync();
|
||||
|
||||
var cmd = PipeSource.FromPipeReader(pipe.Reader) |
|
||||
new Command(Testing.Fixture.Program.FilePath)
|
||||
.WithArguments("echo-stdin");
|
||||
|
||||
var result = await cmd.ExecuteBufferedAsync();
|
||||
|
||||
await Assert.That(result.StandardOutput.Trim()).IsEqualTo("Hello World!");
|
||||
await pipe.Reader.CompleteAsync();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task I_can_execute_a_command_and_pipe_the_stdin_from_a_stream_with_a_custom_buffer_size()
|
||||
{
|
||||
|
|
@ -570,6 +588,37 @@ internal sealed class PipingTests
|
|||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task I_can_execute_a_command_and_pipe_the_stdout_to_a_pipe_writer()
|
||||
{
|
||||
// Arrange
|
||||
var pipe = new Pipe();
|
||||
var cmd = new Command(Testing.Fixture.Program.FilePath)
|
||||
.WithArguments(["generate", "blob", "--length", "100000"]) |
|
||||
PipeTarget.ToPipeWriter(pipe.Writer);
|
||||
|
||||
// Act
|
||||
using var output = new MemoryStream();
|
||||
var executionTask = cmd.ExecuteAsync();
|
||||
while (true)
|
||||
{
|
||||
var result = await pipe.Reader.ReadAsync();
|
||||
foreach (var segment in result.Buffer)
|
||||
{
|
||||
await output.WriteAsync(segment);
|
||||
}
|
||||
pipe.Reader.AdvanceTo(result.Buffer.End);
|
||||
if (result.IsCompleted)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
await executionTask;
|
||||
await pipe.Reader.CompleteAsync();
|
||||
|
||||
await Assert.That(output.Length).IsEqualTo(100_000);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task I_can_execute_a_command_and_pipe_the_stdout_into_multiple_hierarchical_targets()
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue