pub fn write_object_file(object_hash: &str, store: &[u8]) {
    // Use first 2 digits as the direcectory, and the rest as the file name
    let out_dir = &object_hash[..2];
    let out_filename = &object_hash[2..];
    let out_dir_path = format!("gitrs/objects/{}", &out_dir);
    let out_path = format!("{}/{}", &out_dir_path, &out_filename);

    let dir_exists = Path::new(&out_dir_path).exists();
    let path_exists = Path::new(&out_path).exists();

    if !dir_exists {
        fs::create_dir(&out_dir_path).expect("Could not create new directory for object database");
    }

    if !path_exists {
        let out_file = fs::File::create(&out_path).expect("Could not create object file");

        let mut encoder = ZlibEncoder::new(out_file, flate2::Compression::default());
        encoder
            .write_all(store)
            .expect("Could not write object file");
    }
}
/// Write the given store out to the object database, using the object has as its key
///
/// A store consists of a header and the content to be stored
/// A header is the object type and length of the content
Write the given store out to the object database, using the object has as its key
A store consists of a header and the content to be stored
A header is the object type and length of the content
Write the given store out to the object database using the object has as its key A store consists of a header and the content to be stored A header is the object type and length of the content
pub fn write_object_file(object_hash: &str, store: &[u8]) {
    // Use first 2 digits as the direcectory, and the rest as the file name
    let out_dir = &object_hash[..2];
    let out_filename = &object_hash[2..];
    let out_dir_path = format!("gitrs/objects/{}", &out_dir);
    let out_path = format!("{}/{}", &out_dir_path, &out_filename);
    let dir_exists = Path::new(&out_dir_path).exists();
    let path_exists = Path::new(&out_path).exists();
    if !dir_exists {
        fs::create_dir(&out_dir_path).expect("Could not create new directory for object database");
    }
    if !path_exists {
        let out_file = fs::File::create(&out_path).expect("Could not create object file");
        let mut encoder = ZlibEncoder::new(out_file, flate2::Compression::default());
        encoder
            .write_all(store)
            .expect("Could not write object file");
    }
}
pub fn write_object_file ( object_hash : & str , store : & [ u8 ] ) { // Use first 2 digits as the direcectory, and the rest as the file name let out_dir = & object_hash [ .. 2 ] ; let out_filename = & object_hash [ 2 .. ] ; let out_dir_path = format ! ( " " out_dir ) ; let out_path = format ! ( " " out_dir_path out_filename ) ; let dir_exists = Path :: new ( & out_dir_path ) . exists ( ) ; let path_exists = Path :: new ( & out_path ) . exists ( ) ; if ! dir_exists { fs :: create_dir ( & out_dir_path ) . expect ( " " ) ; } if ! path_exists { let out_file = fs :: File :: create ( & out_path ) . expect ( " " ) ; let mut encoder = ZlibEncoder :: new ( out_file , flate2 :: Compression :: default ( ) ) ; encoder . write_all ( store ) . expect ( " " ) ; } }
Write the given store out to the object database, using the object has as its key
A store consists of a header and the content to be stored
A header is the object type and length of the content
Write the given store out to the object database using the object has as its key A store consists of a header and the content to be stored A header is the object type and length of the content
object_hash
&str
store
&[u8]
object_hash
&str
store
&[u8]