/// <summary> /// Read a Base64 encoded line. /// </summary> /// <param name="client">The client to read from.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>The decoded Base64 string.</returns> async Task <string> ReadBase64EncodedLineAsync(INetworkClient client, CancellationToken cancellationToken) { var text = await client.ReadLineAsync(Encoding.ASCII, cancellationToken).ConfigureAwait(false); return(text == null ? String.Empty : Encoding.UTF8.GetString(Convert.FromBase64String(text))); }
/// <summary> /// Read a line from the byte stream. /// </summary> /// <param name="client">The stream to read a line from.</param> /// <param name="encoding">The encoding to use when converting to a string representation.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>The string that was read from the stream.</returns> public static async Task <string> ReadLineAsync(this INetworkClient client, Encoding encoding, CancellationToken cancellationToken = default) { if (client == null) { throw new ArgumentNullException(nameof(client)); } var blocks = await client.ReadLineAsync(cancellationToken).ConfigureAwait(false); return(blocks.Count == 0 ? null : encoding.GetString(blocks.SelectMany(block => block).ToArray())); }
/// <summary> /// Read a Base64 encoded line. /// </summary> /// <param name="client">The client to read from.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>The decoded Base64 string.</returns> async Task <string> ReadBase64EncodedLineAsync(INetworkClient client, CancellationToken cancellationToken) { var text = await client.ReadLineAsync(Encoding.ASCII, cancellationToken).ReturnOnAnyThread(); return(Encoding.UTF8.GetString(Convert.FromBase64String(text))); }