MCPcopy
hub / github.com/TheAlgorithms/Python / read_file_binary

Function read_file_binary

data_compression/lempel_ziv.py:11–25  ·  view source on GitHub ↗

Reads given file as bytes and returns them as a long string

(file_path: str)

Source from the content-addressed store, hash-verified

9
10
11def 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
28def add_key_to_lexicon(

Callers 1

compressFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected