mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Fix possible issue with BOM detection
This commit is contained in:
@@ -203,9 +203,13 @@ namespace SabreTools.Library.IO
|
|||||||
/// <link>http://stackoverflow.com/questions/3825390/effective-way-to-find-any-files-encoding</link>
|
/// <link>http://stackoverflow.com/questions/3825390/effective-way-to-find-any-files-encoding</link>
|
||||||
public static Encoding GetEncoding(string filename)
|
public static Encoding GetEncoding(string filename)
|
||||||
{
|
{
|
||||||
|
// Try to open the file
|
||||||
|
FileStream file = TryOpenRead(filename);
|
||||||
|
if (file == null)
|
||||||
|
return Encoding.Default;
|
||||||
|
|
||||||
// Read the BOM
|
// Read the BOM
|
||||||
var bom = new byte[4];
|
var bom = new byte[4];
|
||||||
FileStream file = FileExtensions.TryOpenRead(filename);
|
|
||||||
file.Read(bom, 0, 4);
|
file.Read(bom, 0, 4);
|
||||||
file.Dispose();
|
file.Dispose();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user