diff --git a/src/Docker.DotNet/MultiplexedStreamReader.cs b/src/Docker.DotNet/MultiplexedStreamReader.cs new file mode 100644 index 00000000..7e7e8b47 --- /dev/null +++ b/src/Docker.DotNet/MultiplexedStreamReader.cs @@ -0,0 +1,48 @@ +using System.Collections.Generic; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Docker.DotNet; + +namespace Docker.DotNet +{ + public class MultiplexedStreamReader + { + private readonly MultiplexedStream _stream; + + public MultiplexedStreamReader(MultiplexedStream stream) + { + _stream = stream; + } + + public async Task ReadLineAsync(CancellationToken cancellationToken) + { + + var line = new List(); + + var buffer = new byte[1]; + + while (!cancellationToken.IsCancellationRequested) + { + var res = await _stream.ReadOutputAsync(buffer, 0, 1, cancellationToken); + + if (res.Count == 0) + { + return null; + } + + else if (buffer[0] == '\n') + { + break; + } + + else + { + line.Add(buffer[0]); + } + } + + return Encoding.UTF8.GetString(line.ToArray()); + } + } +}