# lazyget
> Lazy artifact downloader with local caching.
[](https://crates.io/crates/lazyget)
[](https://vi-is-ramen.github.io/book/en/my-crates/lazyget)
[](https://opensource.org/licenses/MIT)
[](https://opensource.org/licenses/Apache-2.0)
`lazyget` provides a simple, atomic caching layer for downloading or generating artifacts.
Perfect for build tools, template engines, or any workflow where you want to avoid redundant work.
## Features
- **Atomic operations**: Uses temp directories and atomic renames to prevent partial/corrupted cache entries
- **Sync & Async**: Choose the API that fits your project
- **Zero-fuss**: Only `thiserror`, `sha2`, and `hex` (async mode adds optional `tokio`)
- **Idempotent**: Calling `fetch` multiple times with the same ID invokes your closure only once
## Quick Start
Add to your dependencies:
```shell
cargo add lazyget
```
Basic usage:
```rust
use lazyget::{fetch, make_id};
let cache_dir = std::env::temp_dir().join("my-app-cache");
let id = make_id("https://example.com/artifact.zip", Some("v1.2.3"));
let path = fetch(&cache_dir, &id, |dir| {
// Download or generate your artifact into `dir`
std::fs::write(dir.join("result.txt"), "hello")?;
Ok(())
})?;
println!("Artifact ready at: {:?}", path);
```
## Documentation
Full API reference and advanced usage examples are available in the [book](https://vi-is-ramen.github.io/book/en/my-crates/lazyget).
## License
MIT OR Apache-2.0