Implementation to pass test

This commit is contained in:
Edoardo Bezzeccheri 2025-05-07 08:52:52 +00:00
parent c21246f34f
commit c881808ed6

View file

@ -20,9 +20,13 @@ def fix_file(file_obj: IO[bytes]) -> int:
last_character = file_obj.read(1)
# last_character will be '' for an empty file
if last_character not in {LF, CR} and last_character != b'':
# Check if file uses CRLF endings
file_obj.seek(0, os.SEEK_SET)
content = file_obj.read()
ending = CRLF if CRLF in content else LF
# Needs this seek for windows, otherwise IOError
file_obj.seek(0, os.SEEK_END)
file_obj.write(LF)
file_obj.write(ending)
return 1
while last_character in {LF, CR}: