{"id":16602919,"url":"https://github.com/leonardpepa/huffman-compression","last_synced_at":"2025-06-30T08:04:11.132Z","repository":{"id":214004917,"uuid":"730020238","full_name":"Leonardpepa/Huffman-Compression","owner":"Leonardpepa","description":"Huffman Compression  written in go","archived":false,"fork":false,"pushed_at":"2024-01-10T01:32:42.000Z","size":23512,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-17T08:45:45.221Z","etag":null,"topics":["coding-challenges","compression","go","golang","huffman","huffman-compression-algorithm"],"latest_commit_sha":null,"homepage":"https://github.com/Leonardpepa/Huffman-Compression","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Leonardpepa.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2023-12-11T02:52:30.000Z","updated_at":"2024-01-02T02:53:25.000Z","dependencies_parsed_at":"2023-12-25T04:25:11.394Z","dependency_job_id":"f857420c-cfbb-4ff9-ab5f-3046c527c83f","html_url":"https://github.com/Leonardpepa/Huffman-Compression","commit_stats":null,"previous_names":["leonardpepa/huffman-compression"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Leonardpepa%2FHuffman-Compression","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Leonardpepa%2FHuffman-Compression/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Leonardpepa%2FHuffman-Compression/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Leonardpepa%2FHuffman-Compression/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Leonardpepa","download_url":"https://codeload.github.com/Leonardpepa/Huffman-Compression/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242692349,"owners_count":20170228,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["coding-challenges","compression","go","golang","huffman","huffman-compression-algorithm"],"created_at":"2024-10-12T00:45:44.822Z","updated_at":"2025-03-09T12:56:13.352Z","avatar_url":"https://github.com/Leonardpepa.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Huffman Compression written in go\n\n# Purpose\nThis project is a solution for [Write Your Own Compression Tool](https://codingchallenges.fyi/challenges/challenge-huffman)\nbuild for my personal educational purposes\n\n# Description\nThis is an implementation of the huffman compression algorithm. Read how it works here [Huffman Coding Trees](https://opendsa-server.cs.vt.edu/ODSA/Books/CS3/html/Huffman.html)\n\n# Features\n* Compress file\n* Decompress fie\n\n# Implementation Details\n## header - Huffman Topology\nIn order to decode the file we need the original tree that was used to encode it. This implementation\nwrites the tree structure in the file header using preorder traversal, writing 0 for internal nodes\nand 1 followed by the character for each leaf node. The size of the header is stored first followed by the actual information needed to create the tree\n\n## Pseudo EOF\nBecause files operate in byte chunks and this algorithm writes the encoded content bit by bit\nwe need a way to know when the file contents end. To avoid reading any junk bits added to fill the last byte this implementation uses the technique of the Pseudo EOF. The fixed-length code for the Pseudo EOF character is stored at the end of the file. \nThe program stops reading when it encounters the Pseudo EOF. The Pseudo EOF is a character that doesn't occur in the original file.\n\n## Bit Stream\nTo achieve compression the bit strings of the fixed-length codes for each character need to be stored bit by bit in the file.\nBecause go doesn't provide such functionality, bitstream package was implemented from scratch to be able to read and write bits, bytes and runes bit by bit.\n\n# Usage\n```terminal\nUsage: ./huffmanCompression.exe [OPTION] [FILE]\n[OPTIONS]:\n-c FILE ~file to compress\n-d FILE ~file to decompress\n[FILE]:\nthe file specified is the file to compress or decompress,\nwhen compressed the file will be saved with a .hf extension,\nwhen decompressed the file will be saved as a copy of the original file\n```\n\n# Example \n## Compress\n```terminal\n.\\huffmanCompression.exe -c .\\tests\\gutenberg.txt\n2023/12/25 02:52:09 Opening file...  .\\tests\\gutenberg.txt\n2023/12/25 02:52:09 Creating huffman tree...\n2023/12/25 02:52:09 Calculating frequencies...\n2023/12/25 02:52:09 Create priority queue...\n2023/12/25 02:52:09 Build the tree...\n2023/12/25 02:52:09 Calculating variable length codes...\n2023/12/25 02:52:09 Encoding the tree in the header...\n2023/12/25 02:52:09 Encoding the data bit by bit...\n2023/12/25 02:52:09 Encoding finished. File: gutenberg.txt.hf,\nOriginal: (3369045 bytes) compressed: (1919959 bytes)\n```\n## Decompress\n```terminal\n.\\huffmanCompression.exe -d .\\gutenberg.txt.hf\n2023/12/25 02:53:52 Opening file...  .\\gutenberg.txt.hf\n2023/12/25 02:53:52 Reading encoded data... \n2023/12/25 02:53:52 Constructing the huffman tree from the header... \n2023/12/25 02:53:52 Decoding the data... \n2023/12/25 02:53:52 Decoding finished. File: gutenberg.txt, Bytes: 3369045\n```\n\n# How to run\n1. Clone the repo ```git clone https://github.com/Leonardpepa/Huffman-Compression```\n2. Build ```go build```\n3. run on windows```huffmanCompression.exe [OPTION] [FILE]```\n4. run on linux ```.\\huffmanCompression [OPTION] [FILE]```\n5. run all tests ```go test ./...```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleonardpepa%2Fhuffman-compression","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fleonardpepa%2Fhuffman-compression","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleonardpepa%2Fhuffman-compression/lists"}