Skip to content

A simple Rust CLI tool that compresses and decompresses files using the Gzip algorithm, featuring efficient file handling and execution time reporting.

Notifications You must be signed in to change notification settings

Signor1/rust_file_compressor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rust File Compressor and Decompressor

Project Description

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.

Features

  • 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.

Requirements

How to Clone and Set Up the Project

  1. 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
  2. Build the Project:
    Use cargo build to build the project:

    cargo build --release
  3. Run the Executable:
    After building, the binary can be found in the target/release/ directory.

How to Use

1. Compress a File

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

2. Decompress a File

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

Testing the Tool

Included Sample File (input.txt)

The repository already includes a sample file named input.txt that you can use for testing compression and decompression:

  1. Compress input.txt:

    cargo run --release -- compress input.txt compressed.gz
  2. Verify Compression: Check that compressed.gz is created:

    ls -lh compressed.gz
  3. Decompress compressed.gz:

    cargo run --release -- decompress compressed.gz output.txt
  4. Verify Decompression: Compare input.txt and output.txt:

    diff input.txt output.txt

    If there is no output, the files are identical.

Error Handling

  • Ensure the correct number of arguments are provided:

    • Compress: Requires 3 arguments (compress, input_file and output_file.gz).
    • Decompress: Requires 3 arguments (decompress, input_file.gz and output_file).

    Example error:

    Usage: compress <source> <target> OR decompress <source> <target>
    
  • The program will exit gracefully if a file does not exist or permissions are insufficient.

Dependencies

This project uses the following crate:

  • flate2 - Provides Gzip compression and decompression.

Contribution

Feel free to fork this repository, make improvements, and submit a pull request. Suggestions and issues are welcome!

License

This project is licensed under the MIT License.

Contact

For any questions or feedback, feel free to reach out:

About

A simple Rust CLI tool that compresses and decompresses files using the Gzip algorithm, featuring efficient file handling and execution time reporting.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages