aboutsummaryrefslogtreecommitdiff
path: root/src/utils.rs
diff options
context:
space:
mode:
authoromagdy7 <omar.professional8777@gmail.com>2024-06-05 20:56:37 +0300
committeromagdy7 <omar.professional8777@gmail.com>2024-06-05 20:56:37 +0300
commitc79e7fa761196e50407c5de18977a4f9d40445c9 (patch)
treed2543accc1139b5d8ad1e9ba84db23736aa7d87c /src/utils.rs
parent4e0078e7bac5a8b3e7e267a1562590d1300dac64 (diff)
downloadtiny-server-c79e7fa761196e50407c5de18977a4f9d40445c9.tar.xz
tiny-server-c79e7fa761196e50407c5de18977a4f9d40445c9.zip
feat: Added basic handling of Content-Encoding header
Diffstat (limited to 'src/utils.rs')
-rw-r--r--src/utils.rs22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/utils.rs b/src/utils.rs
new file mode 100644
index 0000000..e9d2ef1
--- /dev/null
+++ b/src/utils.rs
@@ -0,0 +1,22 @@
+use std::fs::File;
+use std::io::{self, Read, Write};
+
+pub fn save_bytes_to_file(bytes: &[u8], file_path: &str) -> io::Result<()> {
+ let mut file = File::create(file_path)?;
+ file.write_all(bytes)?;
+ Ok(())
+}
+
+pub fn read_file_as_bytes(path: &str) -> io::Result<Vec<u8>> {
+ // Open the file in read-only mode
+ let mut file = File::open(path)?;
+
+ // Create a buffer to hold the file contents
+ let mut buffer = Vec::new();
+
+ // Read the file contents into the buffer
+ file.read_to_end(&mut buffer)?;
+
+ // Return the buffer
+ Ok(buffer)
+}