summaryrefslogtreecommitdiffstats
path: root/crates/common/download/examples/simple_download.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/common/download/examples/simple_download.rs')
-rw-r--r--crates/common/download/examples/simple_download.rs23
1 files changed, 23 insertions, 0 deletions
diff --git a/crates/common/download/examples/simple_download.rs b/crates/common/download/examples/simple_download.rs
new file mode 100644
index 00000000..821ac0e3
--- /dev/null
+++ b/crates/common/download/examples/simple_download.rs
@@ -0,0 +1,23 @@
+use anyhow::Result;
+use download::Downloader;
+use json_sm::DownloadInfo;
+
+/// This example shows how to use the `downlaoder`.
+#[tokio::main]
+async fn main() -> Result<()> {
+ // Create Download metadata.
+ let url_data = DownloadInfo::new(
+ "https://file-examples-com.github.io/uploads/2017/02/file_example_CSV_5000.csv",
+ );
+
+ // Create downloader instance with desired file path and target directory.
+ let downloader = Downloader::new("test_download", &None, "/tmp");
+
+ // Call `download` method to get data from url.
+ let () = downloader.download(&url_data).await?;
+
+ // Call cleanup method to remove downloaded file if no longer necessary.
+ let () = downloader.cleanup().await?;
+
+ Ok(())
+}