Multiple data compression using C,
INTRODUCTION TO PROJECT
All digital data is stored in form of binary 0s and 1s internally. Working on embedded devices that are memory constrained these files need to be managed efficiently and effectively. Also when transferring file over the network, larger the file size larger is the bandwidth requirement to transfer the same. Hence the requirement of some technique that could take less space and less bandwidth for transmission.
One such technique that can be used for saving memory is compressing the files using some algorithm so that they acquire less space on disk. This technique not only serves the purpose of consuming less space but also provides data security since the file that will be generated after the compression is usually not in human-readable form. Since a normal file does not use all the 255 characters of ASCII table,representing each character by one byte consumes a lot more space. Thus if each distinct character in a file can be represented by fewer bits same data can be saved in much less space;hence accomplishing the purpose.
Here’s the simple stepwise working of the project:-
COMPRESSION
1.) Open the file to be compressed.
2.) Find the distinct characters in the file and store it in an array(master array).
3.) From the master array find the maximum number of bits required to represent each distinct character in compressed file.
4.) Read the file character by character.
5.) Replace each character with the index of the corresponding character in master array.
6.) Manipulate the indexes in the form of 1 byte using shift operations.
7.) Write the manipulated indexes to the compressed file.
8.) Store the master array in other file so that it could be used at the time of decompression.
DECOMPRESSION
1.) Open the compressed file.
2.) Open the file containing master array and store it in array.
3.) Form the master array find out the number of bits used to represent each character.
4.) Read the compressed file character by character.
5.) From this read characters filter out the actual ASCII characters using shift operations and indexes.
6.) Save the filtered out ASCII characters to new file.
Besides this the project can further be enhanced if the master array is also encrypted and this master array is used as the decryption key between the compressing and decompressing programs.
Finally the project was successfully implemented with the very good compression ratio. Also the project was implemented using two techniques;one was using the structured approach based on the number of bits required and the other was a general purpose program in which only a single piece of code could compress or decompress the file.