Giter VIP home page Giter VIP logo

huffman-text-compression's Introduction

Huffman Text Compression

A C# library for text compression, storage, and retrieval using the Huffman code.

Usage

string text = "breathe, breathe in the air";
string filename = "lyrics.huf";

CompressionInfo info = HuffmanCompressor.Encode(text, filename);
Console.WriteLine(info);

string decodedText = HuffmanCompressor.Decode(filename);
Console.WriteLine(decodedText);

File Format

The compressed file consists of three sections: metadata, encoded tree, and encoded text.

The metadata is stored in the first 4 bytes of the file and consists of four numbers:

  • ffv (6 bits) The file format version. This number is intended for backward compatibility and currently has a value of 0.
  • l_tree (18 bits) The size of the encoded tree, in bytes.
  • b_tree (4 bits) The number of the useful bits in the last byte of the encoded tree.
  • b_text (4 bits) The number of the useful bits in the last byte of the encoded text.

The structure of a compressed file looks like this:

     6 bits  18 bits  4 bits   4 bits   l_tree bytes
     ------- -------- -------- -------- -------------- --------------
BOF |  ffv  | l_tree | b_tree | b_text | encoded tree | encoded text | EOF
     ------- -------- -------- -------- -------------- --------------
     \________________________________/
                  metadata

huffman-text-compression's People

Contributors

soroushj avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.