Solved

Compression!!!

Posted on 1999-01-11
10
460 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Suggested Solutions

Title # Comments Views Activity
Put text in a picture ASP.NET C# 2 61
TT Auto Dashboard 13 95
Create Files based on Cell Values in a Range in Excel 12 43
Sub or Function is not defined 6 43
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

830 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