diff options
| author | omagdy7 <omar.professional8777@gmail.com> | 2024-06-05 20:56:37 +0300 |
|---|---|---|
| committer | omagdy7 <omar.professional8777@gmail.com> | 2024-06-05 20:56:37 +0300 |
| commit | c79e7fa761196e50407c5de18977a4f9d40445c9 (patch) | |
| tree | d2543accc1139b5d8ad1e9ba84db23736aa7d87c /src/utils.rs | |
| parent | 4e0078e7bac5a8b3e7e267a1562590d1300dac64 (diff) | |
| download | tiny-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.rs | 22 |
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) +} |
