diff options
Diffstat (limited to 'src/utils.rs')
| -rw-r--r-- | src/utils.rs | 15 |
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)?; |
