{"id":20990599,"url":"https://github.com/bhumijgupta/huffman-compression-library","last_synced_at":"2026-03-17T23:09:15.080Z","repository":{"id":97584699,"uuid":"229557385","full_name":"bhumijgupta/huffman-compression-library","owner":"bhumijgupta","description":"A light weight C++ library implementation of huffman coding compression algorithm","archived":false,"fork":false,"pushed_at":"2020-07-07T07:19:07.000Z","size":253,"stargazers_count":9,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-14T20:41:36.684Z","etag":null,"topics":["c","c-plus-plus","compression-algorithm","cpp","cpp-library","file-compression","huffman-coding","huffman-compression-algorithm","huffman-compression-library"],"latest_commit_sha":null,"homepage":"https://bhumijgupta.github.io/huffman-compression-library/","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bhumijgupta.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-12-22T11:27:58.000Z","updated_at":"2025-04-14T21:48:13.000Z","dependencies_parsed_at":"2023-03-18T12:59:13.504Z","dependency_job_id":null,"html_url":"https://github.com/bhumijgupta/huffman-compression-library","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/bhumijgupta/huffman-compression-library","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bhumijgupta%2Fhuffman-compression-library","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bhumijgupta%2Fhuffman-compression-library/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bhumijgupta%2Fhuffman-compression-library/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bhumijgupta%2Fhuffman-compression-library/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bhumijgupta","download_url":"https://codeload.github.com/bhumijgupta/huffman-compression-library/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bhumijgupta%2Fhuffman-compression-library/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30635156,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-17T22:38:22.569Z","status":"ssl_error","status_checked_at":"2026-03-17T22:38:11.804Z","response_time":56,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c","c-plus-plus","compression-algorithm","cpp","cpp-library","file-compression","huffman-coding","huffman-compression-algorithm","huffman-compression-library"],"created_at":"2024-11-19T06:34:34.783Z","updated_at":"2026-03-17T23:09:15.060Z","avatar_url":"https://github.com/bhumijgupta.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# HCL (Huffman Compression Library)\n\n\u003e HCL a custom C++ library that allows file compression using Huffman Compression algorithm.\n\n[![](https://img.shields.io/badge/Try%20Online-repl.it-brightgreen)](https://repl.it/@bhumijgupta/huffman-demo) ![](https://github.com/bhumijgupta/huffman-compression-library/workflows/Unit%20Test/badge.svg) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/2e33d1fc65044a789e07665a674ad806)](https://www.codacy.com/manual/bhumijgupta/huffman-compression-library?utm_source=github.com\u0026utm_medium=referral\u0026utm_content=bhumijgupta/huffman-compression-library\u0026utm_campaign=Badge_Grade) ![GitHub repo size](https://img.shields.io/github/repo-size/bhumijgupta/huffman-compression-library) ![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/bhumijgupta/huffman-compression-library) ![GitHub top language](https://img.shields.io/github/languages/top/bhumijgupta/huffman-compression-library)\n\n## Table of Contents\n\n- [Features](#Features)\n- [Benchmarks](#Benchmarks)\n- [Usage](#Usage)\n  - [Try Online](#Try-Online)\n  - [Try Locally](#Try-Locally)\n- [Methods](#Methods)\n  - [compressFile](#compressFile)\n  - [decompressFile](#decompressFile)\n  - [benchmark](#benchmark)\n- [Performance Comparison](#Performance-Comparison)\n  - [Conclusion](#Conclusion)\n- [Examples](#Examples)\n- [Run tests](#Run-tests)\n- [License](#License)\n- [Author](#Author)\n\n## Features\n\n- Fast and efficient\n- Supports all kinds of files (images, pdf, video, text, etc)\n- High level abstraction methods to be used\n- No need of understanding how compression algorithm works\n- Light weight library\n- Compression ratio of upto 50%\n\n## Benchmarks\n\nBelow is the output for `huffmantool.benchmark()` method\n![output.png](assets/output.png)\n\n## Usage\n\nThere are 2 ways to try the HCL library\n\n### 1. Try Online\n\nTry the HCL library online on my custom repl. [![](https://img.shields.io/badge/Try%20Online-repl.it-blue)](https://repl.it/@bhumijgupta/huffman-demo)\n\n### 2. Try Locally\n\n1.  Clone this repo to your project folder  \n    `git clone https://github.com/bhumijgupta/huffman-compression-library.git hcl`\n\n2.  Import Huffman tool header and create new `huffmantool` object\n\n```C++\n// Filename main.cpp\n#include \"hcl/huffmantool.h\"\n\nint main(){\n    huffmantool ht;\n    .\n    .\n    .\n}\n```\n\n3.  Compile and run file\n\n```bash\ng++ main.cpp \u0026\u0026 ./a.out\n```\n\n## Methods\n\n### compressFile\n\n```C++\ncompressFile(string sourceFile, string compressedFile = \"\") : string\n```\n\nReturns the destination of compressed file.  \nIf the `sourceFile` provided is invalid or cannot be opened, it returns an empty string.\n\nIf no `compressedFile` is provided, `compressedFile` is present at the same dir as `sourcefile` with prefix `compressed_`\n\n### decompressFile\n\n```C++\ndecompressFile(string compressedFile, string retrievedFile = \"\") : string\n```\n\nReturns the destination of decompressed file.  \nIf the `compressedFile` provided is invalid or cannot be opened, it reurns an empty string.\n\nIf no `retrievedFile` is provided, `retrievedFile` is present at the same dir as `compressedFile` with prefix `decompressed_` and removed `compressed_` prefix (if present)\n\n### benchmark\n\n```C++\nbenchmark(string sourcefile) : void\n```\n\nThis method performs compression and decompression on the sourcefile provided and prints the following stats to the stdout.\n\n```\n--------------------------------------------------------------------------------\n                              B E N C H M A R K\n--------------------------------------------------------------------------------\n\nFiletype                      Filename                      Filesize in bytes\n\nOriginal\nCompressed\nDecompressed\n\n--------------------------------------------------------------------------------\nTime taken to compress file: XYZ microseconds\nTime taken to decompress file: XYZ microseconds\nCompression: XY.Z%\n\n```\n\n\u003cb\u003eNote\u003c/b\u003e: For detailed understanding of code refer to [Wiki](https://github.com/bhumijgupta/huffman-compression-library/wiki).\n\n## Performance Comparison\n\nThe `newfile.txt` is populated using lorem ipsum data from [lipsum.com](https://www.lipsum.com/) and the following data is noticed after executing `main.cpp`.\n\n| Number of characters | Original file size (in bytes) | Compressed file size (in bytes) |\n| :------------------: | :---------------------------: | :-----------------------------: |\n|          10          |              10               |               36                |\n|         100          |              100              |               116               |\n|         1000         |             1000              |               642               |\n|        10000         |             10000             |              5445               |\n|        100000        |            100000             |              53354              |\n\n### Conclusion\n\nThe compression ratio and performance of the Huffman coding depends on the size of input text and the frequency of distinct characters in the file. From the above comparison we can see that the current implementation of huffman coding does not produce positive compression ratio for small files due to the overhead of storing `Huffman Tree` in the compressed file, which is useful at the time of decompression.\n\nBut we notice, as the size of file increases (\u003e=1000 bytes), the compression ratio stays at almost 50%.\n\n## Examples\n\nFollowing are the list of examples\n\n- [CLI tool for file compression](examples/cli_compression.cpp)\n- [Benchmarking tool](examples/benchmark.cpp)\n\n## Run tests\n\n![](https://github.com/bhumijgupta/huffman-compression-library/workflows/Unit%20Test/badge.svg)\n\nThe tests are stored in `tests/` directory. You need to install [googletest](https://www.eriksmistad.no/getting-started-with-google-test-on-ubuntu/) framework to run test.\n\n```bash\ncd tests/\ncmake CMakeLists.txt\nmake\n./runTests\n```\n\n## License\n\n![GitHub](https://img.shields.io/github/license/bhumijgupta/huffman-compression-library)\n\nThis library is licensed under MIT License. The license file can be found [here](LICENSE)\n\n## Author\n\n[![forthebadge](https://forthebadge.com/images/badges/built-with-love.svg)](https://forthebadge.com)\n\n### Bhumij Gupta\n\n![GitHub followers](https://img.shields.io/github/followers/bhumijgupta?label=Follow\u0026style=social) [![LinkedIn](https://img.shields.io/static/v1.svg?label=connect\u0026message=@bhumijgupta\u0026color=success\u0026logo=linkedin\u0026style=flat\u0026logoColor=white)](https://www.linkedin.com/in/bhumijgupta/) ![Twitter URL](https://img.shields.io/twitter/url?style=social\u0026url=http%3A%2F%2Ftwitter.com%2Fbhumijgupta)\n\n---\n\n```C++\nif(repo.isAwesome || repo.isHelpful){\n    StarRepo();\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbhumijgupta%2Fhuffman-compression-library","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbhumijgupta%2Fhuffman-compression-library","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbhumijgupta%2Fhuffman-compression-library/lists"}