Skip to main content

zendriver_fetcher/
lib.rs

1//! Chrome for Testing binary downloader.
2//!
3//! See the [Fetcher chapter](https://turtiesocks.github.io/zendriver-rs/fetcher.html)
4//! of the [zendriver-rs user guide](https://turtiesocks.github.io/zendriver-rs/)
5//! for cache-layout details, offline-mode workflows, and CI integration tips.
6//!
7//! Resolves a [`VersionSpec`] + [`Platform`] pair against the
8//! [Chrome for Testing manifest][cft-manifest], downloads the matching zip,
9//! extracts it into an atomic cache layout, and hands back a path to the
10//! executable.
11//!
12//! Public entry point is [`Fetcher`]; progress is reported through
13//! [`FetcherProgress`] callbacks tagged with a [`FetcherPhase`].
14//!
15//! ```no_run
16//! # async fn ex() -> Result<(), zendriver_fetcher::FetcherError> {
17//! use zendriver_fetcher::{Fetcher, VersionSpec};
18//!
19//! let chrome = Fetcher::new()
20//!     .version(VersionSpec::Latest)
21//!     .ensure_chrome()
22//!     .await?;
23//! println!("Chrome ready at {}", chrome.display());
24//! # Ok(()) }
25//! ```
26//!
27//! [cft-manifest]: https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json
28
29pub mod cache;
30pub mod download;
31pub mod error;
32pub mod extract;
33pub mod fetcher;
34pub mod manifest;
35pub mod platform;
36pub mod resolver;
37pub mod version;
38
39pub use error::FetcherError;
40pub use fetcher::Fetcher;
41pub use platform::Platform;
42pub use version::{Channel, VersionSpec};
43
44/// Lifecycle phase of an in-flight fetch.
45///
46/// Reported via [`FetcherProgress::phase`] so callers can drive a TUI
47/// or log stage-by-stage progress.
48#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
49pub enum FetcherPhase {
50    /// Resolving version + platform against the CFT manifest.
51    Resolving,
52    /// Streaming bytes from the CFT CDN.
53    Downloading,
54    /// Unzipping the downloaded archive.
55    Extracting,
56    /// Verifying integrity (SHA256, executable bit).
57    Verifying,
58    /// All work complete; binary available at the returned path.
59    Done,
60}
61
62/// Progress snapshot emitted by an in-flight fetch.
63#[derive(Debug, Clone)]
64pub struct FetcherProgress {
65    /// Bytes written so far for the current phase.
66    pub downloaded: u64,
67    /// Total bytes expected for the current phase, when known
68    /// (e.g. from the `Content-Length` header during download).
69    pub total: Option<u64>,
70    /// Current phase.
71    pub phase: FetcherPhase,
72}