diff --git a/sdk/src/reader.rs b/sdk/src/reader.rs index d8b7a895a..4216c74c8 100644 --- a/sdk/src/reader.rs +++ b/sdk/src/reader.rs @@ -41,6 +41,7 @@ use crate::{ settings::get_settings_value, status_tracker::StatusTracker, store::Store, + utils::io_utils::uri_to_path, validation_results::{ValidationResults, ValidationState}, validation_status::ValidationStatus, Manifest, ManifestAssertion, @@ -586,22 +587,6 @@ impl Reader { .map(|size| size as usize) } - /// Convert a URI to a file path. (todo: move this to utils) - fn uri_to_path(uri: &str, manifest_label: &str) -> String { - let mut path = uri.to_string(); - if path.starts_with("self#jumbf=") { - // convert to a file path always including the manifest label - path = path.replace("self#jumbf=", ""); - if path.starts_with("/c2pa/") { - path = path.replacen("/c2pa/", "", 1); - } else { - path = format!("{}/{path}", manifest_label); - } - path = path.replace([':'], "_"); - } - path - } - /// Write all resources to a folder. /// /// @@ -626,7 +611,7 @@ impl Reader { for manifest in self.manifests.values() { let resources = manifest.resources(); for (uri, data) in resources.resources() { - let id_path = Self::uri_to_path(uri, manifest.label().unwrap_or("unknown")); + let id_path = uri_to_path(uri, manifest.label().unwrap_or("unknown")); let path = path.as_ref().join(id_path); if let Some(parent) = path.parent() { std::fs::create_dir_all(parent)?; diff --git a/sdk/src/utils/io_utils.rs b/sdk/src/utils/io_utils.rs index c61a9b2e5..7f879a2f3 100644 --- a/sdk/src/utils/io_utils.rs +++ b/sdk/src/utils/io_utils.rs @@ -234,6 +234,22 @@ pub fn wasm_remove_dir_all>(path: P) -> Result<()> { ))? } +/// Convert a URI to a file path. +pub fn uri_to_path(uri: &str, manifest_label: &str) -> String { + let mut path = uri.to_string(); + if path.starts_with("self#jumbf=") { + // convert to a file path always including the manifest label + path = path.replace("self#jumbf=", ""); + if path.starts_with("/c2pa/") { + path = path.replacen("/c2pa/", "", 1); + } else { + path = format!("{}/{path}", manifest_label); + } + path = path.replace([':'], "_"); + } + path +} + #[cfg(test)] mod tests { #![allow(clippy::expect_used)]