This is a simple command-line tool written in Rust that allows you to compress and decompress files using the Gzip format. The tool is designed for efficiency, providing file size reports and execution time for each operation.
- File Compression: Compress any file into Gzip format (
.gz
). - File Decompression: Decompress
.gz
files back to their original state. - Performance Reporting:
- Displays file sizes before and after compression.
- Shows time taken to complete the operation.
- Rust installed on your system. (Follow Rust installation guide if not already installed.)
-
Clone the Repository:
Use the following command to clone the project to your local machine:git clone https://github.com/Signor1/rust_file_compressor.git cd rust_file_compressor
-
Build the Project:
Usecargo build
to build the project:cargo build --release
-
Run the Executable:
After building, the binary can be found in thetarget/release/
directory.
Run the following command to compress a file.
Usage:
cargo run --release -- compress <input_file> <output_file.gz>
Example:
To compress the included input.txt
file to compressed.gz
:
cargo run --release -- compress input.txt compressed.gz
Output:
Original size: 7143 bytes
Compressed size: 2347 bytes
Compression completed in 9.494892ms
Run the following command to decompress a file.
Usage:
cargo run --release -- decompress <input_file.gz> <output_file>
Example:
To decompress compressed.gz
back to output.txt
:
cargo run --release -- decompress compressed.gz output.txt
Output:
Decompressed file size: 7143 bytes
Decompression completed in 534.788µs
The repository already includes a sample file named input.txt
that you can use for testing compression and decompression:
-
Compress
input.txt
:cargo run --release -- compress input.txt compressed.gz
-
Verify Compression: Check that
compressed.gz
is created:ls -lh compressed.gz
-
Decompress
compressed.gz
:cargo run --release -- decompress compressed.gz output.txt
-
Verify Decompression: Compare
input.txt
andoutput.txt
:diff input.txt output.txt
If there is no output, the files are identical.
-
Ensure the correct number of arguments are provided:
- Compress: Requires 3 arguments (
compress
,input_file
andoutput_file.gz
). - Decompress: Requires 3 arguments (
decompress
,input_file.gz
andoutput_file
).
Example error:
Usage: compress <source> <target> OR decompress <source> <target>
- Compress: Requires 3 arguments (
-
The program will exit gracefully if a file does not exist or permissions are insufficient.
This project uses the following crate:
- flate2 - Provides Gzip compression and decompression.
Feel free to fork this repository, make improvements, and submit a pull request. Suggestions and issues are welcome!
This project is licensed under the MIT License.
For any questions or feedback, feel free to reach out:
- GitHub: Signor1