# Struct libfar::farlib::FarArchive
[−] [src]

    pub struct FarArchive {
        pub version: u32,
        pub file_count: u32,
        pub file_list: Vec<FarFileInfo>,
        pub file_data: Vec<FarFile>,
    }

Expand description

Struct containing information about an archive.

Should be created by one of two ways:

1. Calling `FarArchive::new_from_files` if creating an archive from a list of FarFile structs
2. Calling `farlib::test(buffer)` if loading an archive from a file/buffer

## Fields

`version: u32` `file_count: u32` `file_list: Vec<FarFileInfo>` `file_data: Vec<FarFile>`

## Implementations

[src]

### impl FarArchive

[src]

#### pub fn new_from_files(files: Vec<FarFile>) -> FarArchive

Creates a new FarArchive struct from a list of FarFile structs. Important when creating a new archive.

##### Examples

    // file_names is a Vec<String> containing the names of the files
    use std::fs;
    use libfar::farlib;
    let mut file_list = Vec::new();
    for file in file_names {
        let file_name = file.split("/").last().unwrap();
        let file_size = fs::metadata(file.clone()).expect("Failed to get file size").len();
        let file_data = fs::read(file.clone()).expect("Failed to read file");
        let file_obj = farlib::FarFile {
        name: file_name.to_string(),
        size: file_size as u32,
        data: file_data
        };
        file_list.push(file_obj);
    }

    let archive = farlib::FarArchive::new_from_files(file_list);

[src]

#### pub fn load_file_data(self, original_file: &Vec<u8>) -> FarArchive

Loads file data into a FarArchive struct, used if a FarFileInfo struct is not sufficient.

##### Examples

    // buffer is a Vec<u8> containing the contents of a .far file
    use libfar::farlib;
    let test = farlib::test(&buffer);
    match test {
       Ok(archive) => {
           let archive = archive.load_file_data(&buffer);
      }
      Err(e) => {
        println!("{} is not a valid archive: {}", archive_name, e);
      }
    }

[src]

#### pub fn to_vec(self) -> Vec<u8>

Creates a buffer representing the contents of a FarArchive struct. Can be written to a file to create a .far archive.

##### Examples

    // archive is a FarArchive struct
    // archive_name is the name of the file we will write the archive to
    use std::fs;
    use std::io::Write;
    use libfar::farlib;
    let buffer = archive.to_vec();
    let mut file = fs::File::create(archive_name.clone()).expect("Failed to create file");
    file.write_all(&*archive_obj.to_vec()).expect("Failed to write file");

## Auto Trait Implementations

### impl RefUnwindSafe for FarArchive

### impl Send for FarArchive

### impl Sync for FarArchive

### impl Unpin for FarArchive

### impl UnwindSafe for FarArchive

## Blanket Implementations

[src]

### impl<T> Any for T where
T: 'static + ?Sized,

[src]

#### pub fn type_id(&self) -> TypeId

Gets the `TypeId` of `self`. Read more

[src]

### impl<T> Borrow<T> for T where
T: ?Sized,

[src]

#### pub fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more

[src]

### impl<T> BorrowMut<T> for T where
T: ?Sized,

[src]

#### pub fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more

[src]

### impl<T> From<T> for T

[src]

#### pub fn from(t: T) -> T

Performs the conversion.

[src]

### impl<T, U> Into<U> for T where
U: From<T>,

[src]

#### pub fn into(self) -> U

Performs the conversion.

[src]

### impl<T, U> TryFrom<U> for T where
U: Into<T>,

#### type Error = Infallible

The type returned in the event of a conversion error.

[src]

#### pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.

[src]

### impl<T, U> TryInto<U> for T where
U: TryFrom<T>,

#### type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

[src]

#### pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.