## What is nvHTAR Gzip?
nvHTAR Gzip is a powerful open-source library for creating and extracting TAR (Tape Archive) files. It enables developers to compress and decompress files or directories using the Gzip compression algorithm. This library is designed to be lightweight, efficient, and easy to integrate into your projects.
## Key Features
### 1. Gzip Compression
nvHTAR Gzip supports Gzip compression, allowing you to efficiently compress files or directories into TAR archives. This helps reduce file sizes, making data transfer and storage more efficient.
### 2. TAR Extraction
With nvHTAR Gzip, you can easily extract TAR archives, retrieving the original files and directories. This is particularly useful when working with compressed archives received from external sources or generated by other tools.
### 3. Fast and Efficient
This library is optimized for speed and efficiency, ensuring swift compression and extraction operations even for larger files and directories. The underlying Gzip algorithm is highly efficient, resulting in smaller file sizes and faster processing times.
### 4. Easy Integration
nvHTAR Gzip is incredibly easy to integrate into your projects. Whether you’re working with iOS, macOS, or other platforms, it provides a simple and intuitive interface to handle TAR compression and extraction tasks.
## How to Use nvHTAR Gzip
### Installation
To use nvHTAR Gzip in your project, follow these steps:
1. Install the nvHTAR Gzip library via Cocoapods by adding the following line to your Podfile:
“`
pod ‘nvHTARGzip’
“`
2. Run `pod install` in your project directory.
3. Import the library using:
“`
import nvHTARGzip
“`
### Compressing Files and Directories
1. Create an instance of `nvHTARGzip`.
“`swift
let compressor = nvHTARGzip()
“`
2. Specify the source directory or file path for compression.
“`swift
compressor.sourcePath = “/path/to/source”
“`
3. Provide the destination TAR file path.
“`swift
compressor.destinationPath = “/path/to/destination.tar.gz”
“`
4. Call the `compress()` method to initiate the compression process.
“`swift
compressor.compress { (success, error) in
if success {
// Compression successful
} else {
// Handle error
}
}
“`
### Extracting TAR Archives
1. Create an instance of `nvHTARGzip`.
“`swift
let extractor = nvHTARGzip()
“`
2. Specify the source TAR file path for extraction.
“`swift
extractor.sourcePath = “/path/to/source.tar.gz”
“`
3. Provide the destination directory path to store the extracted files.
“`swift
extractor.destinationPath = “/path/to/destination”
“`
4. Call the `extract()` method to initiate the extraction process.
“`swift
extractor.extract { (success, error) in
if success {
// Extraction successful
} else {
// Handle error
}
}
“`
## Example Usage
“`swift
import nvHTARGzip
let compressor = nvHTARGzip()
compressor.sourcePath = “/path/to/source”
compressor.destinationPath = “/path/to/destination.tar.gz”
compressor.compress { (success, error) in
if success {
print(“Compression successful”)
} else {
print(“Compression error: \(error?.localizedDescription ?? “”)”)
}
}
let extractor = nvHTARGzip()
extractor.sourcePath = “/path/to/source.tar.gz”
extractor.destinationPath = “/path/to/destination”
extractor.extract { (success, error) in
if success {
print(“Extraction successful”)
} else {
print(“Extraction error: \(error?.localizedDescription ?? “”)”)
}
}
“`
## Conclusion
nvHTAR Gzip is a versatile library that simplifies the creation and extraction of TAR archives using Gzip compression. It offers a lightweight and efficient solution for developers working with compression tasks in their iOS or macOS projects. Get started with nvHTAR Gzip and enjoy the benefits of reduced file sizes and faster operations.