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

Function read_file_binary

data_compression/lempel_ziv_decompress.py:10–24  ·  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

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

Callers 1

compressFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected