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: u32file_count: u32file_list: Vec<FarFileInfo>file_data: Vec<FarFile>

Implementations

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);

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);
  }
}

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

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.