Skip to content

Commit

Permalink
Download bmap from remote source
Browse files Browse the repository at this point in the history
When downloading the image from a remote source, the bmap will also be searched
remotely and downloaded. The bmap url will be the same as image url, but replacing
the final extension with ".bmap".

Signed-off-by: Rafael Garcia Ruiz <rafael.garcia@collabora.com>
  • Loading branch information
Razaloc committed Dec 12, 2022
1 parent 5f3fad9 commit 43ff1e8
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions bmap-rs/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ fn find_bmap(img: &Path) -> Option<PathBuf> {
}
}

fn find_remote_bmap(mut url: Url) -> Result<Url> {
let mut path = PathBuf::from(url.path());
path.set_extension("bmap");
url.set_path(path.to_str().unwrap());
Ok(url)
}

trait ReadSeekForward: SeekForward + Read {}
impl<T: Read + SeekForward> ReadSeekForward for T {}

Expand Down Expand Up @@ -213,12 +220,10 @@ fn copy_local_input(c: Copy) -> Result<()> {

async fn copy_remote_input(c: Copy) -> Result<()> {
let url = c.image.url()?;
let bmap = find_bmap(&PathBuf::from(url.path())).unwrap();
println!("Found bmap file: {}", bmap.display());
let bmap_url = find_remote_bmap(url.clone())?;

let mut b = File::open(&bmap).context("Failed to open bmap file")?;
let mut xml = String::new();
b.read_to_string(&mut xml)?;
let xml = reqwest::get(bmap_url.clone()).await?.text().await?;
println!("Found bmap file: {}", bmap_url);

let bmap = Bmap::from_xml(&xml)?;
let mut output = tokio::fs::OpenOptions::new()
Expand Down

0 comments on commit 43ff1e8

Please sign in to comment.