Skip to content

Commit

Permalink
Work around server gz issues
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Dec 1, 2023
1 parent 415751c commit 0d59b7e
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/http_assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,30 @@ impl AssetReader for HttpAssetReader {
let (x, rest) = path.split_once('_').unwrap();
// The tile servers we're using have their files gzipped, so we download that and unzip it
// transparently and act as if there's a .glb file there.
let path = format!("{}lod1/{}/{x}/{rest}.gz", self.base_url, TILE_ZOOM);
let ext = if cfg!(target_arch = "wasm32") {
// The server signals the websocket to add .gz and unpack, but does that for `.gz` files, too.
// So if we try to download a `.gz` file, we get an error because we get the decompressed
// version of the file?!
""
} else {
".gz"
};
let path = format!("{}lod1/{}/{x}/{rest}{ext}", self.base_url, TILE_ZOOM);
info!("loading {path}");
let mut bytes_compressed = Vec::new();
bevy_web_asset::WebAssetReader::Https
.read(Path::new(&path))
.await?
.read_to_end(&mut bytes_compressed)
.await?;

let mut decoder = GzDecoder::new(bytes_compressed.as_slice());
if cfg!(target_arch = "wasm32") {
bytes = bytes_compressed;
} else {
let mut decoder = GzDecoder::new(bytes_compressed.as_slice());

decoder.read_to_end(&mut bytes)?;
decoder.read_to_end(&mut bytes)?;
}
} else {
let path = format!("{}{path}", self.base_url);
bevy_web_asset::WebAssetReader::Https
Expand Down

0 comments on commit 0d59b7e

Please sign in to comment.