diff options
Diffstat (limited to 'src/common.rs')
-rw-r--r-- | src/common.rs | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/common.rs b/src/common.rs new file mode 100644 index 0000000..4a622f5 --- /dev/null +++ b/src/common.rs @@ -0,0 +1,26 @@ +pub mod hash; +pub mod json; +pub mod mime; +pub mod slot_map; +pub mod sqlite; + +use std::{fs::File, path::PathBuf}; + +use data_encoding::Encoding; +use data_encoding_macro::new_encoding; +use rand::{thread_rng, Rng}; + +pub const BASE32: Encoding = new_encoding! { + symbols: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567", + translate_from: "abcdefghijklmnopqrstuvwxyz", + translate_to: "ABCDEFGHIJKLMNOPQRSTUVWXYZ", +}; + +pub fn temp_file() -> std::io::Result<(PathBuf, File)> { + let key: [u8; 16] = thread_rng().gen(); + + let mut path = std::env::temp_dir(); + path.push(format!("carton-{}", BASE32.encode(&key))); + + Ok((path.clone(), File::create_new(path)?)) +} |