Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Tagged as

Go to top

Fast and Simple Huffman Compressor

, 2 Apr 2012
Fast and simple huffman compressor
binary30.zip
huffman.exe
simple_huffman_src.zip
new_huffman.dev
source30.zip
/*                                                                            */
/*    Service unit for simple_Huffman class   v.1.0   (c) 2010 Jan Mojzis     */
/*      Notes:                                                                */
/*            x console syntax: <input> <output> <c/d> /compress/decompress   */
/*                                                                            */
#include <stdlib.h>
#include "new_huffman.cpp"
#include <stdio.h>
int main(int argc, char *argv[])
{
    if (argc < 4) { printf("syntax: program <INPUT> <OUTPUT> <c/d>\n"); system("PAUSE"); return 0; }
    
    FILE *finput, *foutput;
    BYTE *input, *output = NULL;
    int delka;
    int skomprimovanych;
    BYTE op = (BYTE) argv[3][0];
    /* open files */       
    finput = fopen(argv[1], "rb");
    if (!finput) { printf("error upon opening %s\n", argv[1]); system("PAUSE"); return 0; }
    foutput = fopen(argv[2], "wb");
    if (!foutput) { printf("error upon opening %s\n", argv[2]); system("PAUSE"); fclose(finput); return 0; }

    /* get the length of input */
    fseek(finput, 0L, SEEK_END);
    delka = ftell(finput);
    fseek(finput, 0L, SEEK_SET);
    
    /* read input */
    input = new BYTE[delka];
    fread(input, 1, delka, finput);
    simple_Huffman *huf = new simple_Huffman();
    if (op == 'c')
    {
       output = new BYTE[1024+(2*delka)]; // pre istotu, nasinec nikdy nevie
       int outsize = huf->Compress(input, delka, output);
       setvbuf(foutput, (char *)output, _IOFBF, outsize); // pre zrychlenie zapisu     
       fwrite(output, outsize, 1, foutput);
    }
    if (op == 'd')
    {      
       int outsize = huf->Decompress(input, delka, output);
       setvbuf(foutput, (char *)output, _IOFBF, outsize); // pre zrychlenie zapisu     
       fwrite(output, outsize, 1, foutput);
    }
    fclose(finput);
    fclose(foutput);
    delete huf;
    if (output)
      delete output;
    delete input;
    return EXIT_SUCCESS;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Jan Mojzis
Software Developer (Junior) SOMI Systems
Slovakia Slovakia
Got 1st and 2nd degree from computer science in 2011 on university of Matej Bel, city of Banska Bystrica. Currently work for computer-oriented company SOMI Systems in Slovakia.
Working for SOMI Systems a.s., http://somi.sk/

| Advertise | Privacy | Mobile
Web02 | 2.8.140922.1 | Last Updated 2 Apr 2012
Article Copyright 2010 by Jan Mojzis
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid