change ownership for efficiency gains
This commit is contained in:
parent
218489cb37
commit
8878eb3b3c
|
@ -12,8 +12,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
let args: Vec<String> = env::args().collect();
|
||||
for arg in &args[1..] {
|
||||
let mut infile = File::open(arg)?;
|
||||
let mut archive: JodOne = infile.read_le()?;
|
||||
let entries = archive.extract();
|
||||
let archive: JodOne = infile.read_le()?;
|
||||
let entries = archive.unpack();
|
||||
let dir = PathBuf::from(format!("{}.d", arg));
|
||||
for (name, data) in entries {
|
||||
let full_path = dir.join(name);
|
||||
|
|
|
@ -40,16 +40,16 @@ impl std::fmt::Debug for JodOneEntry {
|
|||
}
|
||||
|
||||
impl JodOne {
|
||||
pub fn extract(&mut self) -> BTreeMap<PathBuf, Vec<u8>> {
|
||||
pub fn unpack(self) -> BTreeMap<PathBuf, Vec<u8>> {
|
||||
let mut map = BTreeMap::new();
|
||||
for entry in &self.entries {
|
||||
for entry in self.entries {
|
||||
debug!("{:?}", entry);
|
||||
let os_string = OsString::from_vec(entry.name.0.iter()
|
||||
.map(|c| if char::from(*c) == '\\' { std::path::MAIN_SEPARATOR as u8 } else { *c })
|
||||
let os_string = OsString::from_vec(entry.name.0.into_iter()
|
||||
.map(|c| if char::from(c) == '\\' { std::path::MAIN_SEPARATOR as u8 } else { c })
|
||||
.collect());
|
||||
let key = PathBuf::from(os_string);
|
||||
if entry.size_dec == 0 {
|
||||
map.insert(key, entry.data.clone());
|
||||
map.insert(key, entry.data.into_inner());
|
||||
} else {
|
||||
// TODO: improve prs crate to use size_dec hint?
|
||||
let dec_buf = prs::decompress::Decompressor::new(&*entry.data).decompress();
|
||||
|
|
Loading…
Reference in New Issue