Solved

Compression!!!

Posted on 1999-01-11
10
467 Views
Last Modified: 2008-03-10
I need to write a file compression routine in VB6 (!).
Speed is not an issue, file security and space saving are however. I realise this a large and vague area and that it may be 'out of place' on such a site. I am hoping that perhaps source code is already available on which to base my own code. If it is not, I mearly need pointing in the right direction.

I realise the basis for compression is repetition but can't currently see how to implement it!

Thanks in advance...
0
Comment
Question by:lbowers
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +2
10 Comments
 
LVL 12

Accepted Solution

by:
mark2150 earned 350 total points
ID: 1455468
First, why write a compressor when you can get PKZIP for free? Easiest way is to drive PKZIP from a command line shell from VB6. This will give you really good compression and compatibility with the rest of the world. You can password protect the .ZIPs.

Now, if you're dead set on rolling your own there are a variety of ways of compressing data. Some methods are very simple and others are much more complex. For example a simple method is run-length encoding. In this method each string can be stored as itself if there is no repeat or a marker followed by a count and the character to be repeated. This allows you to compress long strings of repeated characters (best case) about 85:1 (3 bytes representing 255 bytes of data) Sadly, most data is not that sloppy.

Other approaches involve tokenizing by frequency. This is similar to how Morse code works. The most common symbol in english, E, is encoded as the shortest possible token, dot. Other symbols are ranked by frequency and progressivly longer tokens are used. Sometimes a symbol is a pair or larger group of characters.

Selection of a compression method is data dependent, different flavors of data will compress better using different approaches. Straight ASCII text, for example, is a seven bit code. Recognizing that there are eight bits in a byte immediately tells you that there is at least 12.5% "gas" in an ASCII file. If you really wanted to, you could pack eight ASCII characters into seven bytes of data just by "bit packing".

Anyway, there are entire volumes on encoding theory and its a fertile field. However, again, PKZIP gives very close to theoretical compression in the majority of cases and is easy to integrate into your product.

If you're compressing 'on the fly' for data storage efficiency this is really a false economy in that disk drive space has been dropping in cost faster than CPU cycles and is predicted to continue to do so.

M

0
 
LVL 3

Expert Comment

by:idt
ID: 1455469
I am not sure why you want to tackle this on your own, many shareware/cheapware solutions exist, however, I am here to help, not judge

for $50 you can download source code (Delphi) for zip compatable compression (supports passwording).. This Delphi code (pascal) would probably be the easiest to port to VB.. I found many asm routines but they were also impossible to read.

http://members.xoom.com/boylank/kpgb3.htm

hope this helps
0
 

Author Comment

by:lbowers
ID: 1455470
I do not really want to use any commercial external/internal solutions, as I fully intend to use the final compression routines in an application I'm writing at work. My boss will not want to pay out for any additional costs to a third party ;)
Internal routines are the *only* solutions where he's concerned.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Expert Comment

by:idt
ID: 1455471
Tell your boss to give his head a shake, he will pay far more to have you write the routines, debug the routines, provide support when they fail, etc etc..

0
 
LVL 12

Expert Comment

by:mark2150
ID: 1455472
Yeah, and a *license* for PKZIP was only $50 the last time I bought one. (been a while tho) - Ask your boss how much programming time he can get for $50 - Hell you've spent *THAT* just researching the question! (grin)

M

0
 
LVL 5

Expert Comment

by:chewhoung
ID: 1455473
0
 
LVL 5

Expert Comment

by:chewhoung
ID: 1455474
It's a free OCX
0
 
LVL 3

Expert Comment

by:vikiing
ID: 1455475
I have Pascal code for zipping and unzipping files (they're hanging over the Web, totally free), but they are too big to paste here. If you want them, put me a mail.


0
 
LVL 12

Expert Comment

by:mark2150
ID: 1455476
Hey vikiing! Send them to me too! (please!)

Mark_Lambert@ntsc.navy.mil

M

0
 
LVL 5

Expert Comment

by:chewhoung
ID: 1455477
To lbowers:
so, which option you go for?

To vikiing:
if you don't mind, send a copy too to chewhoung@yahoo.com.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question