Fix possible issue with BOM detection

This commit is contained in:
Matt Nadareski
2020-10-07 13:19:33 -07:00
parent 4325c0b7ce
commit 348a2a2bcb

View File

@@ -203,9 +203,13 @@ namespace SabreTools.Library.IO
/// <link>http://stackoverflow.com/questions/3825390/effective-way-to-find-any-files-encoding</link>
public static Encoding GetEncoding(string filename)
{
// Try to open the file
FileStream file = TryOpenRead(filename);
if (file == null)
return Encoding.Default;
// Read the BOM
var bom = new byte[4];
FileStream file = FileExtensions.TryOpenRead(filename);
file.Read(bom, 0, 4);
file.Dispose();