Crates.io | fsp |
lib.rs | fsp |
version | 0.4.2 |
source | src |
created_at | 2024-11-28 02:25:42.834307 |
updated_at | 2024-11-30 01:33:59.274512 |
description | File System Plus is a package that provide create, update and delete operation on file syteme |
homepage | https://github.com/O-Boxe/stdlib/tree/fsp---file-system-%2B |
repository | https://github.com/O-Boxe/stdlib/tree/fsp---file-system-%2B |
max_upload_size | |
id | 1463840 |
size | 13,653 |
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
he take 1 parametre :
path
: the path of the folder or the filereturn type :
bool
exemple :
let file_exists = file_exists("../uploads/testDeCreation/001.txt");
println!("file is present ? -> {file_exists}");
he take 1 parametre :
path
: the path of the filereturn 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()
he take 2 parametres :
content
: the content of the file (string)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 createdreturn 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_to_file()
he take 2 parametres :
file_path
: the path of the file that you want to apopend contentcontent
: the content you want tu appendreturn type :
io::Result<()>
exemple :
append_to_file("../uploads/testDeCreation/001.txt", "\n some txt \n").expect("Error");
for uploading a file there is 2 functions :
upload_file_from()
he take 2 parametres :
from_path
: the path of the file that you want to uploadto_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 createdreturn 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 :
from_path
: the path of the file that you want to uploadto_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 createdcallback
: a callback with 1 parametres, the passed parameters is a f64 and that is the progress of the downloaded filereturn 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),
}
for deleting there is 2 functions :
delete_file()
he take 1 parametres :
target_path
: the path of the filereturn 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 :
target_path
: the path of the folderreturn 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 :
target_path
: the path of the folder or the folderreturn 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");