pub fn decompress(file_buffer: Vec<u8>) -> Result<Vec<u8>, String>
Expand description
Decompresses a file in the specified format.
This function takes in a vector of bytes representing the file buffer, which is the entire contents of the file in memory. It then iterates over the file buffer to find the sector type, and returns an error if it is not found.
The function then reads the expected length and CRC value of the decompressed data from the file buffer, and uses a Huffman decoding function to decrypt the Huffman set in the file buffer. It checks that the decrypted length matches the expected length, and returns an error if these values do not match.
The function then calculates the CRC value of the file buffer and the decrypted data,
and compares it to the expected value. If these values do not match, the function
returns an error. Finally, if all checks pass, the function returns the concatenation
of the file buffer and the decrypted data as a Vec<u8>
.
§Arguments
file_buffer
- AVec<u8>
representing the file buffer.
§Returns
- If the sector type is not found, or if the decrypted length and expected length do not
match, or if the calculated CRC value and expected CRC value do not match, the function
returns an error as a
String
. - Otherwise, the function returns the concatenation of the file buffer and the decrypted
data as a
Vec<u8>
.