From d60e9fd0f685fa3eda3b20ebf193a484a8ff9bd3 Mon Sep 17 00:00:00 2001 From: Spencer Young Date: Tue, 24 Mar 2020 22:19:01 -0700 Subject: [PATCH] don't read whole file to detect encoding --- yamllint/cli.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/yamllint/cli.py b/yamllint/cli.py index d314481..d84c6f0 100644 --- a/yamllint/cli.py +++ b/yamllint/cli.py @@ -31,14 +31,14 @@ from yamllint.linter import PROBLEM_LEVELS def determine_encoding(file): with io.open(file, 'rb') as raw_file: - data = raw_file.read() - if data.startswith(codecs.BOM_UTF16_LE): - encoding = 'utf-16-le' - elif data.startswith(codecs.BOM_UTF16_BE): - encoding = 'utf-16-be' - else: - encoding = 'utf-8' - return encoding + data = raw_file.read(4) + if data.startswith(codecs.BOM_UTF16_LE): + encoding = 'utf-16-le' + elif data.startswith(codecs.BOM_UTF16_BE): + encoding = 'utf-16-be' + else: + encoding = 'utf-8' + return encoding def find_files_recursively(items, conf):