How to convert file to base64 UTF 8 little endian

Good day!

I convert binary file into char array:

var bytes = File.ReadAllBytes(@"file.wav");
char[] outArr = new char[(int)(Math.Ceiling((double)bytes.Length / 3) * 4)];
var result = Convert.ToBase64CharArray(bytes, 0, bytes.Length, outArr, 0,  Base64FormattingOptions.None);

string resStr = new string(outArr);

So, is it little endian? And does it convert to UTF-8?

Thank you!

Jon Skeet
people
quotationmark

You don't have any UTF-8 here - and UTF-8 doesn't have an endianness anyway, as its code unit size is just a single byte.

Your code would be simpler as:

var bytes = File.ReadAllBytes(@"file.wav");
string base64 = Convert.ToBase64String(bytes);

If you then write the string to a file, that would have an encoding, which could easily be UTF-8 (and will be by default), but again there's no endianness to worry about.

Note that as base64 text is always in ASCII, each character within a base64 string will take up a single byte in UTF-8 anyway. Even if UTF-8 did have different representations for multi-byte values, it wouldn't be an issue here.

people

See more on this question at Stackoverflow