Browse Source

first commit

Thomas 1 year ago
commit
03ed16a60d
4 changed files with 97 additions and 0 deletions
  1. 1 0
      .gitignore
  2. 57 0
      Cargo.lock
  3. 8 0
      Cargo.toml
  4. 31 0
      src/lib.rs

+ 1 - 0
.gitignore

@@ -0,0 +1 @@
+/target

+ 57 - 0
Cargo.lock

@@ -0,0 +1,57 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+version = 3
+
+[[package]]
+name = "adler"
+version = "1.0.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
+
+[[package]]
+name = "base64"
+version = "0.22.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6"
+
+[[package]]
+name = "cfg-if"
+version = "1.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
+
+[[package]]
+name = "crc32fast"
+version = "1.4.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3"
+dependencies = [
+ "cfg-if",
+]
+
+[[package]]
+name = "flate2"
+version = "1.0.30"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5f54427cfd1c7829e2a139fcefea601bf088ebca651d2bf53ebc600eac295dae"
+dependencies = [
+ "crc32fast",
+ "miniz_oxide",
+]
+
+[[package]]
+name = "miniz_oxide"
+version = "0.7.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08"
+dependencies = [
+ "adler",
+]
+
+[[package]]
+name = "pandora_lib_igv"
+version = "0.1.0"
+dependencies = [
+ "base64",
+ "flate2",
+]

+ 8 - 0
Cargo.toml

@@ -0,0 +1,8 @@
+[package]
+name = "pandora_lib_igv"
+version = "0.1.0"
+edition = "2021"
+
+[dependencies]
+base64 = "0.22.1"
+flate2 = "1.0.30"

+ 31 - 0
src/lib.rs

@@ -0,0 +1,31 @@
+use base64::engine::general_purpose::URL_SAFE_NO_PAD;
+use base64::Engine;
+use flate2::write::DeflateEncoder;
+use flate2::Compression;
+use std::io::prelude::*;
+
+/// Compress string and encode in a URL safe form
+fn compress_string(s: &str) -> String {
+    // Convert string to bytes
+    let bytes = s.as_bytes();
+
+    // Compress the bytes using deflate
+    let mut encoder = DeflateEncoder::new(Vec::new(), Compression::default());
+    encoder.write_all(bytes).expect("Failed to write bytes");
+    let compressed_bytes = encoder.finish().expect("Failed to compress bytes");
+
+    // Encode the compressed bytes to base64
+    URL_SAFE_NO_PAD.encode(compressed_bytes)
+}
+
+#[cfg(test)]
+mod tests {
+    use super::*;
+
+    #[test]
+    fn it_works() {
+        let input_str = "your_string_here";
+        let compressed_str = compress_string(input_str);
+        println!("Compressed and URL-safe encoded string: {}", compressed_str);
+    }
+}