{"id":13822524,"url":"https://github.com/epwalsh/rust-cached-path","last_synced_at":"2025-04-09T23:18:26.551Z","repository":{"id":41243317,"uuid":"227654652","full_name":"epwalsh/rust-cached-path","owner":"epwalsh","description":"🦀 Rust utility for accessing both local and remote files through a unified interface","archived":false,"fork":false,"pushed_at":"2024-01-09T16:11:08.000Z","size":204,"stargazers_count":29,"open_issues_count":18,"forks_count":15,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-09T23:18:22.866Z","etag":null,"topics":["caching","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/epwalsh.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-12-12T16:54:27.000Z","updated_at":"2024-10-01T15:21:18.000Z","dependencies_parsed_at":"2024-06-20T00:11:24.222Z","dependency_job_id":"e3ef6e82-4912-4f6f-8871-b9ec570eb252","html_url":"https://github.com/epwalsh/rust-cached-path","commit_stats":{"total_commits":115,"total_committers":8,"mean_commits":14.375,"dds":"0.14782608695652177","last_synced_commit":"379efc42c80f42c921081c643563fe133ed92e8c"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/epwalsh%2Frust-cached-path","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/epwalsh%2Frust-cached-path/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/epwalsh%2Frust-cached-path/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/epwalsh%2Frust-cached-path/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/epwalsh","download_url":"https://codeload.github.com/epwalsh/rust-cached-path/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248125593,"owners_count":21051771,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["caching","rust"],"created_at":"2024-08-04T08:02:04.164Z","updated_at":"2025-04-09T23:18:26.527Z","avatar_url":"https://github.com/epwalsh.png","language":"Rust","funding_links":[],"categories":["Rust"],"sub_categories":[],"readme":"# rust-cached-path\n\n[![crates.io](https://img.shields.io/crates/v/cached-path.svg)](https://crates.io/crates/cached-path)\n[![Documentation](https://docs.rs/cached-path/badge.svg)](https://docs.rs/cached-path)\n[![MIT/Apache-2 licensed](https://img.shields.io/crates/l/cached-path.svg)](./LICENSE)\n[![CI](https://github.com/epwalsh/rust-cached-path/workflows/CI/badge.svg)](https://github.com/epwalsh/rust-cached-path/actions?query=workflow%3ACI)\n\n\u003c!--\nDO NOT EDIT BELOW THIS POINT BY HAND!\n\nEverything below this point is automatically generated using cargo-rdme: https://github.com/orium/cargo-rdme\nJust run `make readme` to update.\n--\u003e\n\n\u003c!-- cargo-rdme start --\u003e\n\nThe idea behind `cached-path` is to provide a unified, simple interface for\naccessing both local and remote files. This can be used behind other APIs that need\nto access files agnostic to where they are located.\n\nThis is based on the Python library [`allenai/cached_path`](https://github.com/allenai/cached_path).\n\n## Installation\n\n`cached-path` can be used as both a library and a command-line tool. To install `cached-path`\nas a command-line tool, run\n\n```bash\ncargo install --features build-binary cached-path\n```\n\n## Usage\n\nFor remote resources, `cached-path` downloads and caches the resource, using the ETAG\nto know when to update the cache. The path returned is the local path to the latest\ncached version:\n\n```rust\nuse cached_path::cached_path;\n\nlet path = cached_path(\n    \"https://github.com/epwalsh/rust-cached-path/blob/main/README.md\"\n).unwrap();\nassert!(path.is_file());\n```\n\n```bash\n# From the command line:\n$ cached-path https://github.com/epwalsh/rust-cached-path/blob/main/README.md\n/tmp/cache/055968a99316f3a42e7bcff61d3f590227dd7b03d17e09c41282def7c622ba0f.efa33e7f611ef2d163fea874ce614bb6fa5ab2a9d39d5047425e39ebe59fe782\n```\n\nFor local files, the path returned is just the original path supplied:\n\n```rust\nuse cached_path::cached_path;\n\nlet path = cached_path(\"README.md\").unwrap();\nassert_eq!(path.to_str().unwrap(), \"README.md\");\n```\n\n```bash\n# From the command line:\n$ cached-path README.md\nREADME.md\n```\n\nFor resources that are archives, like `*.tar.gz` files, `cached-path` can also\nautomatically extract the files:\n\n```rust\nuse cached_path::{cached_path_with_options, Options};\n\nlet path = cached_path_with_options(\n    \"https://raw.githubusercontent.com/epwalsh/rust-cached-path/main/test_fixtures/utf-8_sample/archives/utf-8.tar.gz\",\n    \u0026Options::default().extract(),\n).unwrap();\nassert!(path.is_dir());\n```\n\n```bash\n# From the command line:\n$ cached-path --extract https://raw.githubusercontent.com/epwalsh/rust-cached-path/main/test_fixtures/utf-8_sample/archives/utf-8.tar.gz\nREADME.md\n```\n\nIt's also easy to customize the cache location, the HTTP client, and other options\nusing a [`CacheBuilder`](https://docs.rs/cached-path/latest/cached_path/cache/struct.CacheBuilder.html) to construct a custom\n[`Cache`](https://docs.rs/cached-path/latest/cached_path/cache/struct.Cache.html) object. This is the recommended thing\nto do if your application makes multiple calls to `cached_path`, since it avoids the overhead\nof creating a new HTTP client on each call:\n\n```rust\nuse cached_path::Cache;\n\nlet cache = Cache::builder()\n    .dir(std::env::temp_dir().join(\"my-cache/\"))\n    .connect_timeout(std::time::Duration::from_secs(3))\n    .build().unwrap();\nlet path = cache.cached_path(\"README.md\").unwrap();\n```\n\n```bash\n# From the command line:\n$ cached-path --dir /tmp/my-cache/ --connect-timeout 3 README.md\nREADME.md\n```\n\n\u003c!-- cargo-rdme end --\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fepwalsh%2Frust-cached-path","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fepwalsh%2Frust-cached-path","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fepwalsh%2Frust-cached-path/lists"}