INNER CODE UNIT · Rust
load_from_file
tangle-network/blueprint · crates/blueprint-profiling/src/lib.rs:125
pub fn load_from_file(path: impl AsRef<std::path::Path>) -> Result<Self, ProfilingError> {
let content = std::fs::read_to_string(path.as_ref()).map_err(|e| {
ProfilingError::InvalidConfiguration(format!("Failed to read file: {e}"))
})?;
serde_json::from_str(&content).map_err(|e| {
ProfilingError::InvalidConfiguration(format!("JSON deserialization failed: {e}"))
})
}
/// Serialize and compress profiles to bytes (for on-chain storage)
///
/// Uses gzip compression to minimize on-chain storage costs.
/// Typical sizes: 1 job ~80 bytes, 10 jobs ~577 bytes, 50 jobs ~2.7KB
pub fn to_compressed_bytes(&self) -> Result<Vec<u8>, ProfilingError> {
use flate2::write::GzEncoder;
use flate2::Compression;
use std::io::Write;