-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Murat Yildirim
committed
Dec 11, 2024
1 parent
8fbda47
commit f03825d
Showing
9 changed files
with
113 additions
and
78 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,56 @@ | ||
Steps to create a compression tool Unix Command (compression_tool) | ||
# Compression Tool | ||
|
||
- Compile the program | ||
```bash | ||
This is a simple file compression and decompression tool that uses Huffman coding to compress files. The tool supports two primary operations: | ||
|
||
- **Compression**: Compresses an input file and stores the result in an output file. | ||
- **Decompression**: Decompresses a compressed file and stores the result in an output file. | ||
|
||
The tool is used through the command line with the following commands: | ||
|
||
- `cczip` for compression | ||
- `ccunzip` for decompression | ||
|
||
## Steps to Create and Use the Compression Tool | ||
|
||
### 1. Compile the Program | ||
|
||
First, build the program by running the following command: | ||
|
||
```bash | ||
cargo build --release | ||
``` | ||
|
||
- Move the executable to a directory in your PATH | ||
### 2. Move the executables to a directory in your PATH | ||
|
||
To make the tool accessible from anywhere in your terminal, move the compiled executables to a directory that is included in your system's PATH. | ||
|
||
```bash | ||
sudo cp ~/projects/compression_tool/target/release/compression_tool /usr/local/bin/ | ||
sudo cp target/release/cczip /usr/local/bin/ | ||
sudo cp target/release/ccunzip /usr/local/bin/ | ||
``` | ||
|
||
- Verify the installation | ||
### 3. Verify the installation | ||
|
||
To verify the installation, check if the executables are accessible from anywhere in your terminal: | ||
|
||
```bash | ||
compression_tool test.txt | ||
which cczip | ||
which ccunzip | ||
``` | ||
|
||
- Optional: Create a symbolic link | ||
|
||
## Usage | ||
|
||
### 1. Compress a file using cczip | ||
|
||
```bash | ||
sudo ln -s ~/projects/compression_tool/target/release/compression_tool /usr/local/bin/compression_tool | ||
cczip test.txt [test.zip] | ||
``` | ||
|
||
- Check if it is working | ||
### 2. Decompress a file using ccunzip | ||
|
||
```bash | ||
which compression_tool | ||
``` | ||
cczip test.dat [test.txt] | ||
``` | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use std::{fs::File, io::{self, BufReader, BufWriter}}; | ||
use compression_tool::decompression::DecompressionTool; | ||
|
||
fn main() -> io::Result<()> { | ||
// Get the arguments (compressed file and decompressed output file) | ||
let args: Vec<String> = std::env::args().collect(); | ||
if args.len() < 2 || args.len() > 3 { | ||
println!("Usage: ccunzip <input_file> [output_file]"); | ||
return Ok(()); | ||
} | ||
|
||
let input_file_path = &args[1]; // Path to the compressed file | ||
let output_file_path = if args.len() == 3 { | ||
&args[2] | ||
} else { | ||
&format!("{}.decompressed", input_file_path) | ||
}; | ||
|
||
let input_file = File::open(input_file_path)?; | ||
let mut reader = BufReader::new(input_file); | ||
|
||
let output_file = File::create(output_file_path)?; | ||
let mut writer = BufWriter::new(&output_file); | ||
|
||
let decompression_tool = DecompressionTool::new(); | ||
decompression_tool.decompress(&mut reader, &mut writer); | ||
|
||
println!("Decompression completed successfully!"); | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use std::fs::File; | ||
use std::io; | ||
use std::io::{BufReader, BufWriter, Write}; | ||
use compression_tool::compression::CompressionTool; | ||
|
||
fn main() -> io::Result<()> { | ||
// Get the arguments (input file and compressed output file) | ||
let args: Vec<String> = std::env::args().collect(); | ||
if args.len() < 2 || args.len() > 3 { | ||
println!("Usage: cczip <input_file> [output_file]"); | ||
return Ok(()); | ||
} | ||
|
||
let input_file_path = &args[1]; // Path to the input file | ||
let output_file_path = if args.len() == 3 { | ||
&args[2] | ||
} else { | ||
&format!("{}.compressed", input_file_path) | ||
}; | ||
|
||
let input_file = File::open(input_file_path)?; | ||
let mut reader = BufReader::new(input_file); | ||
|
||
let mut compression_tool = CompressionTool::new(); | ||
let output_file = File::create(output_file_path)?; | ||
let mut writer = BufWriter::new(&output_file); | ||
|
||
compression_tool.compress(&mut reader, &mut writer); | ||
writer.flush()?; | ||
|
||
println!("Compression completed successfully!"); | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
pub mod compression; | ||
pub mod decompression; | ||
pub mod huffman; | ||
pub mod huffman; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters