Skip to content

Commit

Permalink
Merge pull request #173 from boxdox/naive-expected-size
Browse files Browse the repository at this point in the history
Estimated filesize calculation
  • Loading branch information
silvia-odwyer authored May 23, 2024
2 parents 4dafcc6 + ff9995d commit 195f51a
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions crate/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,21 @@ impl PhotonImage {
self.height = height;
self.raw_pixels = raw_pixels;
}

/// Calculates estimated filesize and returns number of bytes
pub fn get_estimated_filesize(&self) -> u64 {
let base64_data = self.get_base64();
let padding_count = if base64_data.ends_with("==") {
2
} else if base64_data.ends_with('=') {
1
} else {
0
};

// Size of original string(in bytes) = ceil(6n/8) – padding
((base64_data.len() as f64) * 0.75).ceil() as u64 - padding_count
}
}

/// Create a new PhotonImage from a raw Vec of u8s representing raw image pixels.
Expand Down

0 comments on commit 195f51a

Please sign in to comment.