diff options
Diffstat (limited to 'libs/nak/src/utils.rs')
| -rw-r--r-- | libs/nak/src/utils.rs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/libs/nak/src/utils.rs b/libs/nak/src/utils.rs new file mode 100644 index 0000000..7d7886c --- /dev/null +++ b/libs/nak/src/utils.rs @@ -0,0 +1,19 @@ +//! Shared utility functions used across the application + +use std::error::Error; +use std::fs; +use std::path::Path; + +/// Download a file from URL to the specified path +pub fn download_file(url: &str, path: &Path) -> Result<(), Box<dyn Error>> { + // Ensure parent directory exists + if let Some(parent) = path.parent() { + fs::create_dir_all(parent)?; + } + + let resp = ureq::get(url).call()?; + let mut reader = resp.into_reader(); + let mut file = fs::File::create(path)?; + std::io::copy(&mut reader, &mut file)?; + Ok(()) +} |
