Skip to content

Instantly share code, notes, and snippets.

@sebug
Created May 11, 2015 19:14
Show Gist options
  • Save sebug/ddd82f3a14d152404c46 to your computer and use it in GitHub Desktop.
Save sebug/ddd82f3a14d152404c46 to your computer and use it in GitHub Desktop.
Base 64 streamed in C#
using System;
using System.IO;
using System.Collections.Generic;
using System.Security.Cryptography;
namespace Base64
{
public class Base64Stream
{
public static int Main(string[] args)
{
try
{
return Wain(args, Console.OpenStandardInput(),
Console.OpenStandardOutput());
}
catch (Exception ex)
{
Console.Error.WriteLine(ex.Message);
return 1;
}
}
private static int Wain(IReadOnlyCollection<string> args,
Stream input, Stream output)
{
if (input == null)
{
throw new ArgumentNullException("input");
}
if (output == null)
{
throw new ArgumentNullException("output");
}
using (CryptoStream cs = new CryptoStream(output, new ToBase64Transform(), CryptoStreamMode.Write))
{
input.CopyTo(cs);
}
return 0;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment