Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove Byte Order Mark from a File.ReadAllBytes (byte[])

I have an HTTPHandler that is reading in a set of CSS files and combining them and then GZipping them. However, some of the CSS files contain a Byte Order Mark (due to a bug in TFS 2005 auto merge) and in FireFox the BOM is being read as part of the actual content so it's screwing up my class names etc. How can I strip out the BOM characters? Is there an easy way to do this without manually going through the byte array looking for ""?

like image 719
JC Grubbs Avatar asked Nov 13 '08 20:11

JC Grubbs


1 Answers

Expanding on Jon's comment with a sample.

var name = GetFileName();
var bytes = System.IO.File.ReadAllBytes(name);
System.IO.File.WriteAllBytes(name, bytes.Skip(3).ToArray());
like image 196
JaredPar Avatar answered Oct 14 '22 16:10

JaredPar