Solved

Compression!!!

Posted on 1999-01-11
10
447 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
  • 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
 
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

706 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now