1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use regex::Regex;
use super::dependencies::*;
use crate::Text;
pub struct File;
impl File {
pub fn extension(file_type: Option<FileType>) -> &'static str {
let ftype = validate_enum(file_type, None);
get_random_element(EXTENSIONS.get(ftype).expect("Cant find file_type extensions!").iter())
}
pub fn mime_type(mime_type: Option<MimeType>) -> &'static str {
let mtype = validate_enum(mime_type, None);
get_random_element(MIME_TYPES.get(mtype).expect("Cant find mime_type!").iter())
}
pub fn size(minimum: i32, maximum: i32) -> String {
format!("{} {}", randint(minimum, maximum),
get_random_element(vec!["bytes", "kB", "MB", "GB", "TB"].into_iter()))
}
pub fn file_name(file_type: Option<FileType>) -> String {
let replacer = get_random_element(vec!["_", "-"].into_iter());
let word = Text(Locale::EN).word().trim();
let re = Regex::new(r"\s+").unwrap();
let name = re.replace_all(word, replacer);
let ext = Self::extension(file_type);
format!("{name}{ext}")
}
}