6 releases (3 breaking)
0.4.2 | Nov 30, 2024 |
---|---|
0.3.2 | Nov 28, 2024 |
0.2.1 | Nov 28, 2024 |
0.1.0 | Nov 28, 2024 |
#370 in Filesystem
192 downloads per month
13KB
137 lines
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 :
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 :
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 :
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 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 :
file_path
: the path of the file that you want to apopend contentcontent
: 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 :
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 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 :
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 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 :
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 :
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 :
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");
Dependencies
~4–16MB
~210K SLoC