Skip to content

Commit 5a6e346

Browse files
committed
Download bmap from remote source
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>
1 parent daeced4 commit 5a6e346

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

bmap-rs/src/main.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,13 @@ fn find_bmap(img: &Path) -> Option<PathBuf> {
9494
}
9595
}
9696

97+
fn find_remote_bmap(mut url: Url) -> Result<Url> {
98+
let mut path = PathBuf::from(url.path());
99+
path.set_extension("bmap");
100+
url.set_path(path.to_str().unwrap());
101+
Ok(url)
102+
}
103+
97104
trait ReadSeekForward: SeekForward + Read {}
98105
impl<T: Read + SeekForward> ReadSeekForward for T {}
99106

@@ -196,12 +203,10 @@ fn copy_local_input(source: PathBuf, destination: PathBuf) -> Result<()> {
196203
}
197204

198205
async fn copy_remote_input(source: Url, destination: PathBuf) -> Result<()> {
199-
let bmap = find_bmap(&PathBuf::from(source.path())).unwrap();
200-
println!("Found bmap file: {}", bmap.display());
206+
let bmap_url = find_remote_bmap(source.clone())?;
201207

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

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

0 commit comments

Comments
 (0)