Reads given file as bytes and returns them as a long string
(file_path: str)
| 9 | |
| 10 | |
| 11 | def read_file_binary(file_path: str) -> str: |
| 12 | """ |
| 13 | Reads given file as bytes and returns them as a long string |
| 14 | """ |
| 15 | result = "" |
| 16 | try: |
| 17 | with open(file_path, "rb") as binary_file: |
| 18 | data = binary_file.read() |
| 19 | for dat in data: |
| 20 | curr_byte = f"{dat:08b}" |
| 21 | result += curr_byte |
| 22 | return result |
| 23 | except OSError: |
| 24 | print("File not accessible") |
| 25 | sys.exit() |
| 26 | |
| 27 | |
| 28 | def add_key_to_lexicon( |