MCPcopy Create free account
hub / github.com/PerroEngine/Perro / stream_asset

Function stream_asset

perro_source/io_stack/perro_io/src/asset_io.rs:416–451  ·  view source on GitHub ↗

Stream an asset (for large files)

(path: &str)

Source from the content-addressed store, hash-verified

414 let (project_root_opt, root_has_res_dir, demo_excluded) = {
415 let state = PROJECT_ASSET_STATE
416 .read()
417 .expect("required value must be present");
418 // Demo off (the common case) short-circuits before any pattern work,
419 // and the root detaches with an Arc bump instead of a deep clone.
420 let demo_excluded = state.demo
421 && path.strip_prefix("res://").is_some_and(|relative| {
422 state.demo_excludes.as_deref().is_some_and(|patterns| {
423 let segments = split_path_segments(relative);
424 patterns
425 .iter()
426 .any(|pattern| pattern.matches_segments(&segments))
427 })
428 });
429 (state.root.clone(), state.root_has_res_dir, demo_excluded)
430 };
431 if demo_excluded {
432 return ResolvedPath::Excluded(path.to_string());
433 }
434
435 // Handle user:// paths (always disk)
436 if let Some(stripped) = path.strip_prefix("user://") {
437 let app_name = user_app_name(&project_root_opt);
438
439 #[cfg(target_arch = "wasm32")]
440 {
441 return ResolvedPath::WebUserStorage(user_storage_key(&app_name, stripped));
442 }
443
444 #[cfg(not(target_arch = "wasm32"))]
445 {
446 let base = data_local_dir()
447 .unwrap_or_else(std::env::temp_dir)
448 .join(app_name)
449 .join("data");
450 return ResolvedPath::Disk(base.join(stripped));
451 }
452 }
453
454 if let Some(rest) = path.strip_prefix("dlc://") {

Callers

nothing calls this directly

Calls 7

load_web_user_assetFunction · 0.85
stream_fileMethod · 0.80
resolve_pathFunction · 0.70
as_refMethod · 0.45
readMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected