aboutsummaryrefslogtreecommitdiff
path: root/src/classes
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2025-03-13 19:41:57 +0100
committermetamuffin <metamuffin@disroot.org>2025-03-13 19:41:57 +0100
commit918adb796ebe5099c32148542469b647ee6dec28 (patch)
treececbdc5484455c0e6ac58f5aac3d2be5c5dd6688 /src/classes
parente715b30bb22de1901b70397d25ba7df690c389eb (diff)
downloadunity-tools-918adb796ebe5099c32148542469b647ee6dec28.tar
unity-tools-918adb796ebe5099c32148542469b647ee6dec28.tar.bz2
unity-tools-918adb796ebe5099c32148542469b647ee6dec28.tar.zst
streaminginfo abstraction
Diffstat (limited to 'src/classes')
-rw-r--r--src/classes/streaminginfo.rs31
1 files changed, 29 insertions, 2 deletions
diff --git a/src/classes/streaminginfo.rs b/src/classes/streaminginfo.rs
index cb5209d..5549efc 100644
--- a/src/classes/streaminginfo.rs
+++ b/src/classes/streaminginfo.rs
@@ -1,5 +1,10 @@
-use crate::object::{Value, parser::FromValue};
-use anyhow::Result;
+use std::io::{Read, Seek, SeekFrom};
+
+use crate::{
+ object::{Value, parser::FromValue},
+ unityfs::UnityFS,
+};
+use anyhow::{Result, anyhow, bail};
use serde::Serialize;
#[derive(Debug, Serialize)]
@@ -19,3 +24,25 @@ impl FromValue for StreamingInfo {
})
}
}
+
+impl StreamingInfo {
+ pub fn read(&self, fs: &mut UnityFS<impl Read + Seek>) -> Result<Vec<u8>> {
+ if !self.path.starts_with("archive:") {
+ bail!("StreamingInfo path does not start on archive:")
+ }
+ let nodeinfo = fs
+ .nodes()
+ .iter()
+ .find(|n| self.path.ends_with(&n.name))
+ .ok_or(anyhow!("node with path {:?} not found", self.path))?
+ .to_owned();
+
+ let mut buf = Vec::new();
+
+ let mut node = fs.read(&nodeinfo)?;
+ node.seek(SeekFrom::Start(self.offset))?;
+ node.take(self.size as u64).read_to_end(&mut buf)?;
+
+ Ok(buf)
+ }
+}