h5rs: check URL opens the remote file once

open_arg_whole opened and parsed the remote file through open_arg, then
opened it again to download it, so every `h5rs check URL` probed the
server twice. It now opens the storage once and downloads through the
same block cache (whose first block the probe already filled).

Test: check --data of a file within one block costs exactly one request
(two before).

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
This commit is contained in:
osobh
2026-09-26 18:36:35 -05:00
co-authored by Claude Opus 5.5
parent ef480746da
commit efb88f94e3
2 changed files with 18 additions and 4 deletions
+7 -4
View File
@@ -253,13 +253,14 @@ impl H5 {
/// than `max_download` bytes is refused before anything is read: its
/// length is only what the server claims.
pub fn open_arg_whole(arg: &str, max_download: u64) -> Result<H5> {
let h5 = H5::open_arg(arg)?;
if h5.file.contiguous_bytes().is_some() {
return Ok(h5);
if !is_url(arg) {
return H5::open_arg(arg);
}
let name = shown(arg);
#[cfg(feature = "remote")]
{
// One open (one probe of the server); the download then reads
// through the same cache, the first block already in it.
let storage =
clawhdf5_remote::storage_for_url(arg, &clawhdf5_remote::Options::default())
.map_err(|e| Error::new(format!("{name}: {e}")))?;
@@ -274,7 +275,9 @@ impl H5 {
#[cfg(not(feature = "remote"))]
{
let _ = max_download;
unreachable!("open_arg refuses URLs without the remote feature")
Err(Error::new(format!(
"{name}: URLs need h5rs built with the `remote` feature"
)))
}
}