https://github.com/mr-ravin/ravdec
  
  
    Ravdec is a module written in python, which is based on a Lossless Data Compression Algorithm designed by Mr. Ravin Kumar on 19 September, 2016. This compression algorithm have a fixed compression ratio of 1.1429 in all possible cases, It accepts data of following format: alphabets,numbers, and symbols. It can be  used where the machine generates data at a very fast rate, that it became difficult for other algorithms to calculate the probability of a symbol, as data keeps on getting large, and is transmitted over the network with a much faster rate. In this case also,  the above module, and algorithm gives the same compression ratio. 
    https://github.com/mr-ravin/ravdec
  
compression-methods lossless-compression-algorithm python
        Last synced: 8 months ago 
        JSON representation
    
Ravdec is a module written in python, which is based on a Lossless Data Compression Algorithm designed by Mr. Ravin Kumar on 19 September, 2016. This compression algorithm have a fixed compression ratio of 1.1429 in all possible cases, It accepts data of following format: alphabets,numbers, and symbols. It can be used where the machine generates data at a very fast rate, that it became difficult for other algorithms to calculate the probability of a symbol, as data keeps on getting large, and is transmitted over the network with a much faster rate. In this case also, the above module, and algorithm gives the same compression ratio.
- Host: GitHub
- URL: https://github.com/mr-ravin/ravdec
- Owner: mr-ravin
- License: other
- Created: 2017-02-22T05:20:03.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2025-03-04T08:11:37.000Z (8 months ago)
- Last Synced: 2025-03-04T08:31:50.788Z (8 months ago)
- Topics: compression-methods, lossless-compression-algorithm, python
- Language: Python
- Homepage:
- Size: 33.2 KB
- Stars: 1
- Watchers: 3
- Forks: 2
- Open Issues: 0
- 
            Metadata Files:
            - Readme: README.md
- License: license.txt
 
Awesome Lists containing this project
README
          # π¦ **Ravdec - Lossless Data Compression**
## πΉ **Overview**
Ravdec is a Python module implementing a **lossless data compression** algorithm designed by [Ravin Kumar](https://mr-ravin.github.io) on **September 19, 2016**. This algorithm is designed exclusively for **textual data**, including **alphabets, numbers, and symbols**. The algorithm offers two modes: 
- When `enforced_8char_input=True`, the length of input data must be exactly divisible by **8**, ensuring a **fixed compression ratio of 1.1429**.
- When `enforced_8char_input=False`, the compression ratio starts at **1.0435** for a **24-character input** (minimum required length) and increases with input size, approaching **1.1429** for larger inputs.
---
## π§ **Development Details**
- **π¨βπ» Developer:** [Ravin Kumar](https://mr-ravin.github.io)  
- **π GitHub Repository:** [https://github.com/mr-ravin/ravdec/](https://github.com/mr-ravin/ravdec/)
- **π JavaScript Implementation:** [https://github.com/mr-ravin/ravdecjs/](https://github.com/mr-ravin/ravdecjs/)
---
## π **Compression Ratio**
### β
 **When `enforced_8char_input=False`**
- Compression ratio starts at **1.0435** for a **24-character input** (minimum required length).
- Gradually increases, reaching **1.14** at **912-character length**, and further approaches **1.1429** as input size increases.
- Ideal for handling variable-length text data while still achieving efficient compression.
### π **When `enforced_8char_input=True`**
- Original data length must be exactly divisible by **8**, ensuring a **fixed compression ratio of 1.1429**.
- Much faster, making it suitable for **high-speed data compression**.
- Best for **real-time systems** where data is continuously growing and **frequency-based algorithms are time-consuming**.
---
## β³ **Complexity Analysis**
### **1οΈβ£ `enforced_8char_input = True`**
- β
 **Time Complexity: O(n)**
- β
 **Fixed Compression Ratio (1.1429)**
- β
 **Ideal for continuously growing data**
- β
 **Direct 7-bit conversion per character**
- β
 **No padding calculations**
- β
 **Optimized for speed**
### **2οΈβ£ `enforced_8char_input = False`**
- π **Time Complexity: O(n) (with minor overhead)**
- π **Compression ratio varies (~1.04 - 1.1429)**
- π **Needs Padding Overhead**
- β
 **Direct 7-bit conversion per character**
- π **Padding calculation and storage overhead**
- π **Slower compared to enforced mode**
### π **Comparison Table**
| Mode | Time Complexity | Compression Ratio | Padding Overhead | Best Use Case |
|------|---------------|-----------------|----------------|---------------|
| `enforced_8char_input = True` | **O(n)** | **Fixed (1.1429)** | β No Padding | **High-speed data streams** |
| `enforced_8char_input = False` | **O(n) (with minor overhead)** | **Variable (~1.04 - 1.1429)** | β
 Needs Padding | **General text compression** |
---
## π― **Use Cases**
- **π Log File Compression:** Reduces storage space while maintaining quick retrieval.
- **β‘ High-Speed Data Transmission:** Faster processing with `enforced_8char_input=True`.
- **π Fixed Compression Ratio Scenarios:** Ideal for predictable compression requirements.
- **π Data Archiving:** Efficient text storage without losing information.
- **β³ Real-Time Compression:** `enforced_8char_input=True` ensures immediate compression without extra calculations.
---
## π **Features**
- β
 **Fixed compression ratio** up to **1.1429** for `enforced_8char_input=True`.
- β
 **Supports alphabets, numbers, and symbols**.
- β
 **Optimized for real-time and high-speed data transmission**.
---
## π οΈ **Functions**
### π `file_compression(filename, enforced_8char_input=False)`
Compresses a text file and saves the compressed data with the `.rdc` extension.
### π `file_decompression(filename, enforced_8char_input=False)`
Decompresses a previously compressed `.rdc` file back to its original form.
### π `compression(read_data, enforced_8char_input=False)`
Compresses a string using **7-bit storage**, returning a compressed string.
### π `decompression(compressed_text, enforced_8char_input=False)`
Decompresses a compressed string back to its original form.
---
## π₯ **Installation**
Install using pip:
```sh
pip install ravdec
```
or,
```sh
pip install git+https://github.com/mr-ravin/ravdec.git
```
---
### π **Dependencies:**
- Python >= 3.7
- No additional dependencies required
---
## π **Example Usage**
### β **Compressing and Decompressing Text**
```python
import ravdec
# When enforced_8char_input=True
data = 'Ravdec !'  # Length of data is divisible by 8
# Compress a string with enforced_8char_input=True
compressed_data = ravdec.compression(data, enforced_8char_input=True) # compressed_data is 'Β₯\x87ΒΆLΒΈΓ!'
# Decompress the string
decompressed_data = ravdec.decompression(compressed_data, enforced_8char_input=True)
print(compressed_data)    # Output: 'Β₯\x87ΒΆLΒΈΓ!'
print(decompressed_data)  # Output: 'Ravdec !'
# When enforced_8char_input=False (and input data has length >= 24)
data = 'R'*25
# Compress a string with enforced_8char_input=False
compressed_data = ravdec.compression(data) # by default enforced_8char_input=False
# Decompress the string
decompressed_data = ravdec.decompression(compressed_data) # by default enforced_8char_input=False
print(compressed_data)
print(decompressed_data)
```
### ποΈ **Compressing and Decompressing Files**
```python
import ravdec
original_filename = "inputfile.txt"
compressed_filename = filename+".rdc"
# Compress a file
ravdec.file_compression(original_filename) # saves compressed data in compressed_filename
# Decompress the previously compressed file
ravdec.file_decompression(compressed_filename) # saves the decompressed data in original_filename (got after removing '.rdc' from compressed_filename)
```
---
## π **Copyright License**
```python
Copyright (c) 2016 Ravin Kumar
Website: https://mr-ravin.github.io
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation 
files (the βSoftwareβ), to deal in the Software without restriction, including without limitation the rights to use, copy, 
modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the 
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 
Software.
THE SOFTWARE IS PROVIDED βAS ISβ, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
```