Skip to content

A Rust-based CLI utility for zipping and unzipping files and directories, featuring nested directory support.

Notifications You must be signed in to change notification settings

Signor1/rust_file_zip_and_unzip

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rust Zip/Unzip Utility

This project is a Rust-based command-line utility for compressing files into a ZIP archive and extracting files from a ZIP archive. It demonstrates how to use the zip crate for handling ZIP files in Rust.

Features

  • Zip Files: Compress multiple files and directories into a ZIP archive.
  • Unzip Files: Extract files from an existing ZIP archive.
  • Handles Nested Directories: Automatically includes subdirectories during compression.
  • Cross-Platform: Compatible with Linux, macOS, and Windows.

Prerequisites

  • Rust installed on your machine.

Installation

  1. Clone this repository:
    git clone https://github.com/Signor1/rust_file_zip_and_unzip.git
    cd rust_file_zip_and_unzip
  2. Build the project:
    cargo build --release

Usage

Unzipping a File

To extract files from a ZIP archive:

cargo run -- unzip <filename>

Example:

cargo run -- unzip hello_cargo.zip

This will extract the contents of hello_cargo.zip into the current directory.

Zipping Files

To create a ZIP archive from files and directories:

cargo run -- zip <output_zipfile> <files_to_zip>...

Example:

cargo run -- zip my_archive.zip file1.txt folder1/

This will create a ZIP file named my_archive.zip containing file1.txt and the contents of folder1/.

Project Structure

  • src/main.rs: Contains the main logic for zipping and unzipping files.
  • Dependencies: Uses the zip crate for handling ZIP files.

How It Works

Unzip Functionality

  1. Opens the specified ZIP file.
  2. Iterates through the archive contents.
  3. Extracts files and directories, preserving structure.
  4. Optionally restores file permissions (on Unix-based systems).

Zip Functionality

  1. Creates a new ZIP archive.
  2. Adds specified files to the archive.
  3. Recursively adds contents of directories to the archive.

Example

Given the following directory structure:

work/
  hello_cargo.zip
  file1.txt
  folder1/
    file2.txt
  • To extract hello_cargo.zip:
    cargo run -- unzip hello_cargo.zip
  • To create a new archive:
    cargo run -- zip new_archive.zip file1.txt folder1/

Contributions

Contributions are welcome! Feel free to open issues or submit pull requests.

About

A Rust-based CLI utility for zipping and unzipping files and directories, featuring nested directory support.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages