forked from spinframework/spin
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Yordan Madzhunkov
committed
Jun 20, 2024
1 parent
5fa7311
commit 594e63f
Showing
5 changed files
with
251 additions
and
195 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,47 @@ | ||
|
||
use std::env; | ||
use std::fs; | ||
use std::path::PathBuf; | ||
//extern crate curl; | ||
|
||
use std::io::Write; | ||
use curl::easy::Easy; | ||
use std::io::Write; | ||
|
||
fn main() { | ||
let base_url = "https://raw.githubusercontent.com/blocksense-network/imagenet_openvino/db44329b8e2b3398c9cc34dd56d94f3ce6fd6e21/";//images/0.jpg | ||
let base_url = "https://raw.githubusercontent.com/blocksense-network/imagenet_openvino/db44329b8e2b3398c9cc34dd56d94f3ce6fd6e21/"; //images/0.jpg | ||
|
||
let imagenet_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../../target/test-programs/imagenet"); | ||
let imagenet_path = | ||
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../../target/test-programs/imagenet"); | ||
let images_dir = imagenet_path.join("images"); | ||
fs::create_dir_all(images_dir).unwrap(); | ||
let files = [ | ||
"model.xml", | ||
"model.bin", | ||
"images/0.jpg", | ||
"images/1.jpg", | ||
]; | ||
let files = ["model.xml", "model.bin", "images/0.jpg", "images/1.jpg"]; | ||
for file in files { | ||
try_download(&(base_url.to_owned()+file), &imagenet_path.join(file)).unwrap(); | ||
try_download(&(base_url.to_owned() + file), &imagenet_path.join(file)).unwrap(); | ||
} | ||
|
||
println!("cargo:rerun-if-changed=build.rs"); | ||
} | ||
|
||
fn try_download(url: &str, filename: &PathBuf) -> Result<(), anyhow::Error> { | ||
let mut easy = Easy::new(); | ||
easy.url(url).map_err(|e| anyhow::anyhow!("Error {} when downloading {}", e.to_string(), url))?; | ||
easy.url(url) | ||
.map_err(|e| anyhow::anyhow!("Error {} when downloading {}", e.to_string(), url))?; | ||
|
||
let mut dst = Vec::new(); | ||
{ | ||
let mut transfer = easy.transfer(); | ||
transfer.write_function(|data| { | ||
dst.extend_from_slice(data); | ||
Ok(data.len()) | ||
}).unwrap(); | ||
transfer.perform().map_err(|e| anyhow::anyhow!("Error {} when downloading {}", e.to_string(), url))?; | ||
transfer | ||
.write_function(|data| { | ||
dst.extend_from_slice(data); | ||
Ok(data.len()) | ||
}) | ||
.unwrap(); | ||
transfer | ||
.perform() | ||
.map_err(|e| anyhow::anyhow!("Error {} when downloading {}", e.to_string(), url))?; | ||
} | ||
{ | ||
let mut file = std::fs::File::create(filename)?; | ||
file.write_all(dst.as_slice())?; | ||
} | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.