Created
August 10, 2012 22:07
-
-
Save cbilson/3318522 to your computer and use it in GitHub Desktop.
BOM detector
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Is-BOM-File ($filename) { | |
$bytes = Get-Content -Encoding byte -TotalCount 4 $filename | |
$encoding = [Text.Encoding]::GetEncodings() ` | |
| ForEach { $_.GetEncoding() } ` | |
| Where-Object { -not $_.IsSingleByte } ` | |
| Where-Object { | |
$preamble = $_.GetPreamble() | |
For ($i = 0; $i -lt $preamble.Length; $i++) { | |
if ($bytes[$i] -ne $preamble[$i]) { | |
return $false | |
} | |
$true | |
} | |
} | |
$encoding -ne $null | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment