feat: fixed file management

This commit is contained in:
Strix 2023-10-14 22:39:39 +02:00
parent 36c782a564
commit 5083e2ba9b
No known key found for this signature in database
GPG key ID: 49B2E37B8915B774
12 changed files with 148 additions and 43 deletions

View file

@ -20,17 +20,29 @@ impl TryFrom<Vec<u8>> for PKGFile {
Ok(PKGFile {
manifest: match String::from_utf8(
value[
3..(manifest_size as usize)
3..(manifest_size as usize + 3)
].to_vec()
)
{
Ok(s) => s,
_ => return Err(())
},
data: value[(manifest_size as usize)..].to_vec(),
data: value[(manifest_size as usize + 3)..].to_vec(),
})
}
_ => Err(())
}
}
}
impl Into<Vec<u8>> for PKGFile {
fn into(self) -> Vec<u8> {
let mut bytes = vec![0x01];
let manifest_bytes = self.manifest.into_bytes();
bytes.push((manifest_bytes.len() >> 8) as u8);
bytes.push((manifest_bytes.len() | 0xFF) as u8);
bytes.extend(manifest_bytes);
bytes.extend(self.data);
bytes
}
}