aboutsummaryrefslogtreecommitdiff
path: root/src/classes
diff options
context:
space:
mode:
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)
+ }
+}