public static async ValueTask <string> ToStringAsync( this IStreamProducer producer, Encoding?encoding = default, int copyBufferSize = StreamConsumer.DefaultBufferSize, CancellationToken cancellationToken = default) { await using var consumer = StreamConsumer.ToString(encoding, copyBufferSize); return(await producer.ConsumeAsync(consumer, cancellationToken).ConfigureAwait(false)); }
public async Task EncryptAndDecryptAlternative() { var seed = @"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce elementum nisi vel magna rhoncus, in aliquam ipsum accumsan. Phasellus efficitur lectus quis malesuada aliquet. Proin mattis sagittis magna vitae blandit. Cras vel diam sagittis, fringilla nunc vitae, vehicula mi. Nullam et auctor mi. Proin vel pharetra tortor. Donec posuere elementum risus, et aliquet magna pharetra non. Curabitur volutpat maximus sem at euismod. Fusce porta, lacus vel varius varius, lacus felis faucibus ante, fermentum sollicitudin elit neque rhoncus tortor. Aenean eget turpis consequat, luctus lorem vehicula, ullamcorper erat."; var enc = new EncryptTransformation(); var dec = new DecryptTransformation(); var prod = StreamProducer.FromString(seed, Encoding.ASCII); var cons = StreamConsumer.ToString(Encoding.ASCII); var output = await prod.ConsumeAsync(cons .Chain(dec) .Chain(enc) ); Assert.Equal(seed, output); Assert.True(enc.HasStarted); Assert.True(enc.HasCompleted); Assert.Null(enc.Error); Assert.True(enc.HasBeenDisposed); Assert.True(dec.HasStarted); Assert.True(dec.HasCompleted); Assert.Null(dec.Error); Assert.True(dec.HasBeenDisposed); }
public virtual string Execute([NotNull] params string[] arguments) { #region Sanity checks if (arguments == null) { throw new ArgumentNullException(nameof(arguments)); } #endregion Process process; try { process = GetStartInfo(arguments).Start(); Debug.Assert(process != null); } #region Error handling catch (IOException ex) { throw new IOException(string.Format(Resources.UnableToLaunchBundled, AppBinary), ex); } #endregion var stdout = new StreamConsumer(process.StandardOutput); var stderr = new StreamConsumer(process.StandardError); var stdin = process.StandardInput; InitStdin(stdin); do { HandlePending(stderr, stdin); } while (!process.WaitForExit(50)); stdout.WaitForEnd(); stderr.WaitForEnd(); HandlePending(stderr, stdin); return(stdout.ToString()); }