aboutsummaryrefslogtreecommitdiff
path: root/src/utils.rs
diff options
context:
space:
mode:
authoromagdy7 <omar.professional8777@gmail.com>2024-06-05 22:42:05 +0300
committeromagdy7 <omar.professional8777@gmail.com>2024-06-05 22:42:05 +0300
commitfe378c20c645ca1cb6cc04e95c9afd4c2de5c0e8 (patch)
treeb5848c95a5c12597b952934bae0b85e4b292816c /src/utils.rs
parentc119c9cc4c1b3b01a7c1851993dde0264ad06733 (diff)
downloadtiny-server-fe378c20c645ca1cb6cc04e95c9afd4c2de5c0e8.tar.xz
tiny-server-fe378c20c645ca1cb6cc04e95c9afd4c2de5c0e8.zip
feat: Handled Gzip compression
Diffstat (limited to 'src/utils.rs')
-rw-r--r--src/utils.rs15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/utils.rs b/src/utils.rs
index e9d2ef1..925669c 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -1,6 +1,21 @@
+use flate2::write::GzEncoder;
+use flate2::Compression;
use std::fs::File;
use std::io::{self, Read, Write};
+pub fn encode_gzip_string(input: &str) -> std::io::Result<Vec<u8>> {
+ // Create a buffer to hold the compressed data
+ let mut encoder = GzEncoder::new(Vec::new(), Compression::default());
+
+ // Write the input string into the encoder
+ encoder.write_all(input.as_bytes())?;
+
+ // Finish the encoding process and get the compressed data
+ let compressed_data = encoder.finish()?;
+
+ Ok(compressed_data)
+}
+
pub fn save_bytes_to_file(bytes: &[u8], file_path: &str) -> io::Result<()> {
let mut file = File::create(file_path)?;
file.write_all(bytes)?;