init: initial commit of packager

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

10
pkgfile/Cargo.toml Normal file
View file

@ -0,0 +1,10 @@
[package]
name = "pkgfile"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
manifest = { path = "../manifest" }
tar = "0.4.38"

3
pkgfile/pkgfile.txt Normal file
View file

@ -0,0 +1,3 @@
[pkgfile version (1 byte)][size manifest x256 (1 byte)][size manifest x1 (1 byte)]
[manifest]
[tar file]

36
pkgfile/src/lib.rs Normal file
View file

@ -0,0 +1,36 @@
pub struct PKGFile {
pub manifest: String,
pub data: Vec<u8>,
}
impl TryFrom<Vec<u8>> for PKGFile {
type Error = ();
fn try_from(value: Vec<u8>) -> Result<Self, ()> {
match value[0] {
1 => {
let header: Vec<u32> = value[..3]
.iter()
.map(|v| u32::from(*v))
.collect();
let manifest_size: u32 = ((header[1] << 8) | header[2]);
if manifest_size > value.len() as u32 {
return Err(());
}
Ok(PKGFile {
manifest: match String::from_utf8(
value[
3..(manifest_size as usize)
].to_vec()
)
{
Ok(s) => s,
_ => return Err(())
},
data: value[(manifest_size as usize)..].to_vec(),
})
}
_ => Err(())
}
}
}