Skip to content

Instantly share code, notes, and snippets.

@zplume
Created March 25, 2021 10:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zplume/511bf3393138bb38380ff47f9820e38b to your computer and use it in GitHub Desktop.
Save zplume/511bf3393138bb38380ff47f9820e38b to your computer and use it in GitHub Desktop.
using System.IO;
using System.Text;
public static class StreamExtensions
{
public static string ToEncodedString(this Stream stream, Encoding enc = null)
{
enc = enc ?? Encoding.UTF8;
byte[] bytes = new byte[stream.Length];
stream.Position = 0;
stream.Read(bytes, 0, (int)stream.Length);
string data = enc.GetString(bytes);
return data;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment