prs_rs/
util.rs

1/// Decodes the maximum possible compressed size after compressing a file with provided
2/// `source_len` length.
3///
4/// # Parameters
5///
6/// - `source_len`: Length of the compressed data.
7///
8/// # Returns
9///
10/// The length of the decompressed data at `source`.
11///
12/// # Remarks
13///
14/// A properly compressed PRS file has a theoretical maximum size of 1.125 times the size of the
15/// original input. i.e. (1 byte for every 8 bytes of input).
16///
17/// Up to 2 bytes may be added to that in addition, namely via:
18/// - Rounding file to next byte
19/// - Having to write 00 opcode after a compressed sequence of bytes to terminate.
20pub fn prs_calculate_max_compressed_size(source_len: usize) -> usize {
21    ((source_len * 9) / 8) + 3 // +1 for integer division error
22}