1

I want to compress small text (400 bytes) and decompress it on the other side. If I do it with standard compressor like rar or zip, it writes metadata along with the compressed file and it's bigger that the file itself..

Is there a way to compress the file without this metadata and open it on the other side with known ahead parameters?

Anderson
  • 573
  • 1
  • 4
  • 9

2 Answers2

3

You can do raw deflate compression with zlib. That avoids even the six-byte header and trailer of the zlib format.

However you will find that you still won't get much compression, if any at all, with just 400 bytes of input. Compression algorithms need much more history than that to get rolling, in order to build statistics and find redundancy in the data.

You should consider either a dictionary approach, where you build a dictionary of representative strings to provide the compressor something to work with, or you can consider a sequence of these 400-byte strings to be a single stream that is decompressed as a stream on the other end.

Mark Adler
  • 101,978
  • 13
  • 118
  • 158
0

You can have a look at compression using Huffman codes. As an example look at here and here.

Community
  • 1
  • 1
Javad M. Amiri
  • 594
  • 5
  • 20
  • Tried the Huffman algorithm, from file with 357 bytes it compressed me to 5335 bytes.. Maybe I don't understand how it works? I used this implementation http://code.activestate.com/recipes/576603-huffman-coding-encoderdeconder/ – Anderson Dec 06 '12 at 11:09