Use u64 to describe number of bytes in the Manifest, now that we have a massive GeoTIFF in there that breaks wasm's 2^32 usize limit. #586

This commit is contained in:
Dustin Carlino 2021-03-24 21:23:38 -07:00
parent 61c46461e4
commit ce473928fa
3 changed files with 14 additions and 10 deletions

View File

@ -16,10 +16,11 @@ pub struct Manifest {
pub struct Entry {
/// md5sum of the file
pub checksum: String,
/// Uncompressed size in bytes
pub uncompressed_size_bytes: usize,
/// Uncompressed size in bytes. Because we have some massive files more than 2^32 bytes
/// described by this, explicitly use u64 instead of usize, so wasm doesn't break.
pub uncompressed_size_bytes: u64,
/// Compressed size in bytes
pub compressed_size_bytes: usize,
pub compressed_size_bytes: u64,
}
impl Manifest {

View File

@ -107,7 +107,7 @@ impl<A: AppLike + 'static> State<A> for Picker<A> {
}
// For each city, how many total bytes do the runtime files cost to download?
fn size_per_city(manifest: &Manifest) -> BTreeMap<String, usize> {
fn size_per_city(manifest: &Manifest) -> BTreeMap<String, u64> {
let mut per_city = BTreeMap::new();
for (path, entry) in &manifest.entries {
let parts = path.split("/").collect::<Vec<_>>();
@ -122,7 +122,7 @@ fn size_per_city(manifest: &Manifest) -> BTreeMap<String, usize> {
per_city
}
fn prettyprint_bytes(bytes: usize) -> String {
fn prettyprint_bytes(bytes: u64) -> String {
if bytes < 1024 {
return format!("{} bytes", bytes);
}
@ -220,13 +220,13 @@ pub fn sync_missing_files(timer: &mut Timer) -> Vec<String> {
}
// Bytes downloaded if succesful
fn download(url: &str, local_path: String) -> Result<usize> {
fn download(url: &str, local_path: String) -> Result<u64> {
let mut resp = reqwest::blocking::get(url)?;
if !resp.status().is_success() {
bail!("bad status: {:?}", resp.status());
}
let mut buffer: Vec<u8> = Vec::new();
let bytes = resp.copy_to(&mut buffer)? as usize;
let bytes = resp.copy_to(&mut buffer)?;
info!("Decompressing {} ({})", url, prettyprint_bytes(bytes));
let mut decoder = flate2::read::GzDecoder::new(&buffer[..]);

View File

@ -156,7 +156,7 @@ fn upload(version: String) {
// generate_manifest.
entry.compressed_size_bytes = std::fs::metadata(&remote_path)
.expect(&format!("Compressed {} not there?", remote_path))
.len() as usize;
.len();
(path, entry)
},
) {
@ -254,7 +254,7 @@ fn generate_manifest() -> Manifest {
}
/// Returns (checksum, uncompressed_size_bytes)
fn md5sum(path: &str) -> (String, usize) {
fn md5sum(path: &str) -> (String, u64) {
// since these files can be very large, computes the md5 hash in chunks
let mut file = File::open(path).unwrap();
let mut buffer = [0 as u8; MD5_BUF_READ_SIZE];
@ -267,7 +267,10 @@ fn md5sum(path: &str) -> (String, usize) {
uncompressed_size_bytes += n;
context.consume(&buffer[..n]);
}
(format!("{:x}", context.compute()), uncompressed_size_bytes)
(
format!("{:x}", context.compute()),
uncompressed_size_bytes as u64,
)
}
fn rm(path: &str) {