verboselib.cli.encoding.has_bom()   A
last analyzed

Complexity

Conditions 2

Size

Total Lines 8
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 2
nop 1
1
import codecs
2
3
from pathlib import Path
4
5
6
def has_bom(file_path: Path) -> bool:
7
  with file_path.open("rb") as f:
8
    sample = f.read(4)
9
10
  return (
11
       sample[:3] == b"\xef\xbb\xbf"
12
    or sample.startswith(codecs.BOM_UTF16_LE)
13
    or sample.startswith(codecs.BOM_UTF16_BE)
14
  )
15