mirror of
https://github.com/lifegpc/msg-tool.git
synced 2026-06-14 00:44:26 +08:00
优化 ArchiveContent 接口,改为使用 MemReader 处理数据,提升内存管理效率
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
use crate::ext::io::*;
|
||||
use crate::types::*;
|
||||
use anyhow::Result;
|
||||
use std::io::{Read, Seek, Write};
|
||||
@@ -109,15 +110,22 @@ pub trait ScriptBuilder: std::fmt::Debug {
|
||||
}
|
||||
}
|
||||
|
||||
pub trait ArchiveContent {
|
||||
pub trait ArchiveContent: Read {
|
||||
fn name(&self) -> &str;
|
||||
fn data(&self) -> &[u8];
|
||||
fn is_script(&self) -> bool {
|
||||
self.script_type().is_some()
|
||||
}
|
||||
fn script_type(&self) -> Option<&ScriptType> {
|
||||
None
|
||||
}
|
||||
fn data(&mut self) -> Result<Vec<u8>> {
|
||||
let mut data = Vec::new();
|
||||
self.read_to_end(&mut data)?;
|
||||
Ok(data)
|
||||
}
|
||||
fn to_data<'a>(&'a mut self) -> Result<Box<dyn ReadSeek + 'a>> {
|
||||
Ok(Box::new(MemReader::new(self.data()?)))
|
||||
}
|
||||
}
|
||||
|
||||
pub trait Script: std::fmt::Debug {
|
||||
|
||||
Reference in New Issue
Block a user