aboutsummaryrefslogtreecommitdiff
path: root/src/common.rs
diff options
context:
space:
mode:
authorevuez <julien@mulga.net>2024-04-03 22:43:16 +0200
committerevuez <julien@mulga.net>2024-04-03 22:43:16 +0200
commit43e1a12b5bce11b4a28a53acca243e35c2be6d3e (patch)
tree07d64823718bfee063ab7b3d5721ac1e950ae17c /src/common.rs
downloadcarton-43e1a12b5bce11b4a28a53acca243e35c2be6d3e.tar.gz
Initial commit
Diffstat (limited to 'src/common.rs')
-rw-r--r--src/common.rs26
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)?))
+}