From 43e1a12b5bce11b4a28a53acca243e35c2be6d3e Mon Sep 17 00:00:00 2001 From: evuez Date: Wed, 3 Apr 2024 22:43:16 +0200 Subject: Initial commit --- src/common.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/common.rs (limited to 'src/common.rs') 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)?)) +} -- cgit v1.2.3