fsp

Crates.iofsp
lib.rsfsp
version0.4.2
sourcesrc
created_at2024-11-28 02:25:42.834307
updated_at2024-11-30 01:33:59.274512
descriptionFile System Plus is a package that provide create, update and delete operation on file syteme
homepagehttps://github.com/O-Boxe/stdlib/tree/fsp---file-system-%2B
repositoryhttps://github.com/O-Boxe/stdlib/tree/fsp---file-system-%2B
max_upload_size
id1463840
size13,653
Toutouh Hamza (O-Boxe)

documentation

https://github.com/O-Boxe/stdlib/tree/fsp---file-system-%2B

README

fsp

fsp or file system plus is a crates that provides some function that help you to create, upload, delete files

note : this project is not complete so after updating this package check everytime if everything is compatible with the previous version

verify if a file/folder exists

he take 1 parametre :

  1. path : the path of the folder or the file

return type :

  • bool

exemple :

let file_exists = file_exists("../uploads/testDeCreation/001.txt");

println!("file is present ? -> {file_exists}");

read file

he take 1 parametre :

  1. path : the path of the file

return type :

  • Result<String, io::Error>

exemple :

match read_file_content("../uploads/testDeCreation/001.txt") {
    Ok(content)=>{
        println!("content : {content}")
    },
    Err(e)=> eprintln!("Error : {e}")
}

create file

create_file()

he take 2 parametres :

  1. content : the content of the file (string)
  2. to_path : the path of the file to put the content in, you don't need to check if the folder is created because the function already check if the folders of the output path is already created

return type :

  • Result<(), Box<dyn std::error::Error>>
match create_file(
    String::from("hello wordl"),
    "../uploads/testDeCreation/001.txt"
) {
    Ok(_) => {
        println!("Fichier crée avec succès !")
    }
    Err(e) => eprintln!("Erreur : {}", e),
}

append content to a file

append_to_file()

he take 2 parametres :

  1. file_path : the path of the file that you want to apopend content
  2. content : the content you want tu append

return type :

  • io::Result<()>

exemple :

append_to_file("../uploads/testDeCreation/001.txt", "\n some txt \n").expect("Error");

upload a file

for uploading a file there is 2 functions :

  • upload_file_from
  • upload_file_from_cb

upload_file_from()

he take 2 parametres :

  1. from_path : the path of the file that you want to upload
  2. to_path : the path of the file to put the content in, you don't need to check if the folder is created because the function already check if the folders of the output path is already created

return type :

  • Result<(), Box<dyn std::error::Error>>

exemple :

match upload_file_from(
    "https://server11.mp3quran.net/hazza/001.mp3",
    "../uploads/test/001.mp3"
) {
    Ok(_) => {
        println!("File upload successfully !")
    }
    Err(e) => eprintln!("Error : {}", e),
}

upload_file_from_cb()

he take 3 parametres :

  1. from_path : the path of the file that you want to upload
  2. to_path : the path of the file to put the content in, you don't need to check if the folder is created because the function already check if the folders of the output path is already created
  3. callback : a callback with 1 parametres, the passed parameters is a f64 and that is the progress of the downloaded file

return type :

  • Result<(), Box<dyn std::error::Error>>

exemple :

match upload_file_from_cb(
    "https://server11.mp3quran.net/hazza/001.mp3",
    "../uploads/test/001.mp3",
    |progress|{println!("{}%", progress)}
) {
    Ok(_) => {
        println!("File upload successfully !")
    }
    Err(e) => eprintln!("Erreur : {}", e),
}

delete a file/folder

for deleting there is 2 functions :

  • delete_file
  • delete_folder
  • delete_fof

delete_file()

he take 1 parametres :

  1. target_path : the path of the file

return type :

  • io::Result<()>

exemple :

match delete_file("") {
    Ok(_) => println!("File successfully deleted !"), 
    Err(e) => eprintln!("Error : {}", e) 
}
//or
delete_file("../uploads/testDeCreation/001.txt").expect("Error");

delete_folder()

he take 1 parametres :

  1. target_path : the path of the folder

return type :

  • io::Result<()>

exemple :

match delete_folder("") {
    Ok(_) => println!("File successfully deleted !"), 
    Err(e) => eprintln!("Error : {}", e) 
}
//or
delete_folder("../uploads/testDeCreation/001.txt").expect("Error");

delete_fof() (fof = file or folder)

he take 1 parametres :

  1. target_path : the path of the folder or the folder

return type :

  • io::Result<()>

exemple :

match delete_fof("") {
    Ok(_) => println!("File successfully deleted !"), 
    Err(e) => eprintln!("Error : {}", e) 
}
//or
delete_fof("../uploads/testDeCreation/001.txt").expect("Error");
Commit count: 0

cargo fmt