Fix problem where encoding is not set

This commit is contained in:
Patrick Jentsch 2021-06-22 12:46:01 +02:00
parent fd39246e4b
commit 5139fd9727

View File

@ -27,14 +27,12 @@ parser.add_argument('-c', '--check-encoding',
help='Check encoding of the input file, UTF-8 is used instead') # noqa help='Check encoding of the input file, UTF-8 is used instead') # noqa
args = parser.parse_args() args = parser.parse_args()
if args.check_encoding:
with open(args.input, "rb") as text_file: with open(args.input, "rb") as text_file:
if args.check_encoding: if args.check_encoding:
encoding = chardet.detect(text_file.read())['encoding'] encoding = chardet.detect(text_file.read())['encoding']
else: else:
encoding = 'utf-8' encoding = 'utf-8'
text_file.seek(0)
with open(args.input, "rb") as text_file:
text_md5 = hashlib.md5() text_md5 = hashlib.md5()
for chunk in iter(lambda: text_file.read(128 * text_md5.block_size), b''): for chunk in iter(lambda: text_file.read(128 * text_md5.block_size), b''):
text_md5.update(chunk) text_md5.update(chunk)