Solved

Compression!!!

Posted on 1999-01-11
10
473 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
Independent Software Vendors: 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

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!

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…

717 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