Skip to main content

Module ffile

Module ffile 

Source
Expand description

Custom implementation of std::fs::File

§Example

use frozen_core::ffile::{FrozenFile, FFCfg};

const MID: u8 = 0;

let dir = tempfile::tempdir().unwrap();
let path = dir.path().join("tmp_frozen_file");

let cfg = FFCfg {
    chunk_size: 0x10,
    path: path.to_path_buf(),
    initial_chunk_amount: 0x0A,
};

let file = FrozenFile::new::<MID>(cfg.clone()).unwrap();
assert_eq!(file.length().unwrap(), 0x10 * 0x0A);

let mut data = vec![1u8; 0x10];
assert!(file.pwrite(data.as_mut_ptr(), 0).is_ok());
assert!(file.sync().is_ok());

let mut buf = vec![0u8; data.len()];
assert!(file.pread(buf.as_mut_ptr(), 0).is_ok());
assert_eq!(buf, data);

assert!(FrozenFile::new::<MID>(cfg.clone()).is_err());

assert!(file.delete().is_ok());
assert!(!path.exists());

drop(file);
assert!(FrozenFile::new::<MID>(cfg).is_ok());

Structs§

FFCfg
Config for FrozenFile
FrozenFile
Custom implementation of std::fs::File

Type Aliases§

TFileId
File descriptor of FrozenFile