Struct stac_async::download::Downloader
source · pub struct Downloader<T: Links + Assets + Href + Serialize + Clone> { /* private fields */ }
Expand description
A customizable download structure.
Implementations§
source§impl<T: Links + Assets + Href + Serialize + Clone> Downloader<T>
impl<T: Links + Assets + Href + Serialize + Clone> Downloader<T>
sourcepub fn new(stac: T) -> Result<Downloader<T>>
pub fn new(stac: T) -> Result<Downloader<T>>
Creates a new downloader.
Examples
let item: stac::Item = stac::read("data/simple-item.json").unwrap();
let downloader = stac_async::Downloader::new(item);
sourcepub fn create_directory(self, create_directory: bool) -> Downloader<T>
pub fn create_directory(self, create_directory: bool) -> Downloader<T>
Should the downloader create the output directory?
Defaults to true
.
Examples
let item: stac::Item = stac::read("data/simple-item.json").unwrap();
let downloader = stac_async::Downloader::new(item)
.unwrap()
.create_directory(false);
sourcepub fn with_sender(self, sender: Sender<Message>) -> Downloader<T>
pub fn with_sender(self, sender: Sender<Message>) -> Downloader<T>
Set the sender for messages from this downloader.
Examples
use tokio::sync::mpsc;
use stac_async::Downloader;
use stac::Item;
let (tx, mut rx) = mpsc::channel(100);
let item: Item = stac::read("data/simple-item.json").unwrap();
let downloader = Downloader::new(item)
.unwrap()
.with_sender(tx);
tokio::spawn(async move {
downloader.download(".").await.unwrap()
});
while let Some(message) = rx.recv().await {
dbg!(message);
}
sourcepub async fn download(self, directory: impl AsRef<Path>) -> Result<T>
pub async fn download(self, directory: impl AsRef<Path>) -> Result<T>
Downloads assets to the specified directory.
Consumes this downloader, and returns the modified object.
Examples
let item: stac::Item = stac::read("data/simple-item.json").unwrap();
let downloader = stac_async::Downloader::new(item).unwrap();
let item = downloader.download("outdir").await.unwrap();
Trait Implementations§
Auto Trait Implementations§
impl<T> !RefUnwindSafe for Downloader<T>
impl<T> Send for Downloader<T>where T: Send,
impl<T> Sync for Downloader<T>where T: Sync,
impl<T> Unpin for Downloader<T>where T: Unpin,
impl<T> !UnwindSafe for Downloader<T>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more