Upload and download attachments, and added License file

This commit is contained in:
Daniel García
2018-02-15 00:40:34 +01:00
parent 5cd40c63ed
commit b54684b677
20 changed files with 1147 additions and 199 deletions

View File

@@ -30,7 +30,7 @@ macro_rules! err_handler {
use std::path::Path;
use std::io::Read;
use std::fs::File;
use std::fs::{self, File};
pub fn file_exists(path: &str) -> bool {
Path::new(path).exists()
@@ -48,6 +48,31 @@ pub fn read_file(path: &str) -> Result<Vec<u8>, String> {
Ok(contents)
}
pub fn delete_file(path: &str) -> bool {
fs::remove_file(path).is_ok()
}
const UNITS: [&'static str; 6] = ["bytes", "KB", "MB", "GB", "TB", "PB"];
pub fn get_display_size(size: i32) -> String {
let mut size = size as f64;
let mut unit_counter = 0;
loop {
if size > 1024. {
size /= 1024.;
unit_counter += 1;
} else {
break;
}
};
// Round to two decimals
size = (size * 100.).round() / 100.;
format!("{} {}", size, UNITS[unit_counter])
}
///
/// String util methods