forked from AbleOS/ableos
83 lines
1.8 KiB
Rust
83 lines
1.8 KiB
Rust
use core::fmt;
|
|
|
|
#[derive(Debug, PartialEq, Clone)]
|
|
pub struct PathRep {
|
|
pub location: FileLocations,
|
|
pub file_name: String,
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
pub struct FilePermissions {
|
|
pub read: bool,
|
|
pub write: bool,
|
|
pub execute: bool,
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
pub struct FileMetadata {
|
|
pub file_type: String,
|
|
pub size: usize,
|
|
// pub permissions: FilePermissions,
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq)]
|
|
pub enum FileLocations {
|
|
Bin,
|
|
Config,
|
|
Home,
|
|
}
|
|
impl fmt::Display for FileLocations {
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
write!(f, "{:?}", self)
|
|
}
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
pub struct File {
|
|
pub location: FileLocations,
|
|
pub file_name: String,
|
|
pub meta_data: FileMetadata,
|
|
pub data_pointer: Vec<u8>,
|
|
}
|
|
|
|
impl File {
|
|
/// Write the provided bytes to a file
|
|
pub fn write_bytes(&mut self, bytes: &[u8]) {
|
|
for byte in bytes {
|
|
self.data_pointer.push(*byte);
|
|
}
|
|
|
|
self.meta_data.size = self.data_pointer.len();
|
|
}
|
|
|
|
pub fn new(location: FileLocations, file_name: String, file_type: String) -> Self {
|
|
let bytes: Vec<u8> = vec![];
|
|
let abc123 = bytes;
|
|
|
|
Self {
|
|
location,
|
|
file_name,
|
|
meta_data: FileMetadata { file_type, size: 0 },
|
|
data_pointer: abc123,
|
|
}
|
|
}
|
|
|
|
pub fn size(&self) -> usize {
|
|
self.meta_data.size.clone()
|
|
}
|
|
|
|
pub fn read_to_string(&mut self, _string: &mut String) {
|
|
todo!();
|
|
}
|
|
|
|
pub fn read_and_return(&mut self) -> String {
|
|
String::from_utf8(self.data_pointer.clone()).expect("Found invalid UTF-8")
|
|
}
|
|
}
|
|
|
|
impl fmt::Display for File {
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
write!(f, "{}://{}", self.location, self.file_name)
|
|
}
|
|
}
|