update Tar!
This commit is contained in:
parent
99b69cc14d
commit
26f3d26bc2
|
@ -53,3 +53,69 @@ impl From<[char; 512]> for Header {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<[char; 512]> for Header {
|
||||
fn into(self) -> [char; 512] {
|
||||
let mut header: [char; 512] = ['\0'; 512];
|
||||
|
||||
header[..100].clone_from_slice(&self.filename);
|
||||
header[100..108].clone_from_slice(&self.filemode);
|
||||
header[108..116].clone_from_slice(&self.user_id);
|
||||
header[116..124].clone_from_slice(&self.group_id);
|
||||
header[124..136].clone_from_slice(&self.size);
|
||||
header[136..148].clone_from_slice(&self.modified_time);
|
||||
header[148..156].clone_from_slice(&self.checksum);
|
||||
header[155] = self.typeflag;
|
||||
|
||||
header
|
||||
}
|
||||
}
|
||||
|
||||
// TODO Write tests for this library
|
||||
#[test]
|
||||
fn from2tar() {
|
||||
let mut filename = ['\0'; 100];
|
||||
for (i, c) in "file.txt".chars().enumerate() {
|
||||
filename[i] = c;
|
||||
}
|
||||
|
||||
let header = Header {
|
||||
filename,
|
||||
filemode: ['6', '4', '4', ' ', ' ', ' ', ' ', '\0'],
|
||||
user_id: ['0', '0', '0', '0', '0', '0', '0', '0'],
|
||||
group_id: ['0', '0', '0', '0', '0', '0', '0', '0'],
|
||||
size: ['8', '1', '9', '2', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '\0'],
|
||||
modified_time: ['1', '6', '0', '7', '1', '1', '4', '9', '8', '0', ' ', '\0'],
|
||||
checksum: ['0', '0', '0', '0', '0', '0', ' ', '\0'],
|
||||
typeflag: '0',
|
||||
};
|
||||
let array: [char; 512] = header.try_into().unwrap();
|
||||
// assert_eq!(array)
|
||||
}
|
||||
|
||||
enum Error {
|
||||
InvalidChecksum,
|
||||
InvalidFileData,
|
||||
InvalidTarFormat,
|
||||
InvalidTarHeader,
|
||||
UnsupportedCompression,
|
||||
UnsupportedEncryption,
|
||||
UnsupportedTarFormat,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
enum FileType {
|
||||
Directory,
|
||||
Regular,
|
||||
Other(char),
|
||||
}
|
||||
|
||||
impl From<char> for FileType {
|
||||
fn from(c: char) -> Self {
|
||||
match c {
|
||||
'0' | '\0' => FileType::Regular,
|
||||
'5' => FileType::Directory,
|
||||
_ => FileType::Other(c),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue