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

Function add_file_length

data_compression/lempel_ziv.py:74–83  ·  view source on GitHub ↗

Adds given file's length in front (using Elias gamma coding) of the compressed string

(source_path: str, compressed: str)

Source from the content-addressed store, hash-verified

72
73
74def add_file_length(source_path: str, compressed: str) -> str:
75 """
76 Adds given file's length in front (using Elias gamma coding) of the compressed
77 string
78 """
79 file_length = os.path.getsize(source_path)
80 file_length_binary = bin(file_length)[2:]
81 length_length = len(file_length_binary)
82
83 return "0" * (length_length - 1) + file_length_binary + compressed
84
85
86def write_file_binary(file_path: str, to_write: str) -> None:

Callers 1

compressFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected