//! Scan a real folder through the engine, and read a preview out of it. //! //! ```text //! cargo run -p dr-sync-folder --example scan -- /path/to/photos //! ``` //! //! Exercises the same code the application runs: `dr_sync::scan` driving the //! folder connector, then a ranged `get` of the kind the thumbnail worker //! makes. Reads only — it never writes into the folder it is pointed at. use std::collections::HashMap; use dr_sync::{RemoteBackend, RemoteId, RemotePath}; use dr_sync_folder::FolderBackend; use dr_types::FormatFilter; #[tokio::main(flavor = "current_thread")] async fn main() { let Some(root) = std::env::args().nth(1) else { eprintln!("usage: scan "); std::process::exit(2); }; let backend = match FolderBackend::new(&root) { Ok(b) => b, Err(e) => { eprintln!("{e}"); std::process::exit(1); } }; let caps = backend.capabilities(); println!("{} at {root}", backend.name()); println!( " strategy: {}", dr_sync::SyncStrategy::for_capabilities(caps).describe() ); let started = std::time::Instant::now(); let result = dr_sync::scan( &backend, &RemotePath::root(), &FormatFilter::all(), &HashMap::new(), |_| {}, ) .await .expect("scan"); println!( " {} image(s) in {} director(ies), {:?}", result.images.len(), result.progress.directories_listed, started.elapsed() ); let Some(first) = result.images.first() else { return; }; println!( " first: {} ({} bytes) id {:?}", first.path, first.size, first.id ); // The shape of request the thumbnail worker makes: a header window, not // the whole file. let head = backend .get(&RemoteId::Path(first.path.clone()), Some(0..65536)) .await .expect("ranged read"); println!(" read {} header bytes", head.len()); }