Link to home
Start Free TrialLog in
Avatar of tsa2
tsa2

asked on

Fast File Compression

OK, here is my problem: I need to compress a file into a smaller one (not multiple files into 1).

For example, I have (lets say) COMMAND.COM (which is, lets say, 90K). I want to compress it so it will become COMMAND.CO_, and (for example) will now be 30K.

The only catch is I DO NOT want an activex control or DLL to do this. I found a few nice compression examples out there, but they are too slow.

Does ANYONE know how I can compress a file to a somewhat good extent, and for it to be fast. (IE: one of the modules used Huffman compression, and took 4 minutes compressing Command.Com (which I think is 97K))

If anyone knows of a way WITHOUT DLLs or OCXs, I would appreciate it. Thanks in advance.

If the code is too long, just point me to the correct website.
Avatar of evansg
evansg

you could shell out to COMPRESS.EXE that comes with every windows install.
Avatar of tsa2

ASKER

That would not be an option.
'// Launch the app and store its window handle
lngInst = Shell("C:\COMPRESS -r Source Destination", SW_MINIMIZE)
'// Start the timer
intStart = Timer
blnTimeOut = False
Do While GetModuleUsage(lngInst) > 0
DoEvents
If Abs(Timer - intStart) > 30 Then
blnTimeOut = True
Exit Do
End If
Loop

Avatar of tsa2

ASKER

That would not be an option.
Avatar of Brendt Hess
You are not going to find quick, pure VB compression code.  VB, as a language, does not have the efficient bit manipulation abilities to handle efficient compression.  Thus, the OCXs / DLLs out there for compression.  These are usually written in C/C++, which is much better than VB at this type of bit-twitching.
Using freeware Info-zip libraries in VB:

http://www.vbaccelerator.com/codelib/zip/zipvb.htm
Avatar of tsa2

ASKER

PaulHewes,

I am sorry, but like I said: I do not want OCXs or DLLs.
Then you must want slow.  bhess is right, vb is slow for this kind of work.  You saw it yourself.
As you have already looked into a couple of codes, maybe you can tell me where you found the fastest one. It is almost always possible to optimize codes found on the net to make it *much* faster. ;)
That code is awfully coded (at least I think so) so I think it's possible to do a much better code, I'll be back later tonight when I have more time. I have made some changes and come to 8x faster code but I'll rewrite the Treecreation part too because that code does a lot of unneccessary string manipulations. ;)
I tried to compact the command.com file but because the command.com contains all ASCII values the Huffman Encoding is not specially good. Huffman encoding is best on for example English text where characters like i,e etc are more usual than for example b,h etc. How good the Huffman Encoding is depends on the kind of text you want to compress.
ASKER CERTIFIED SOLUTION
Avatar of Vbmaster
Vbmaster

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tsa2

ASKER

I am testing it..

I will get back to you.
Avatar of tsa2

ASKER

It takes pretty long to compress a 24 meg file.

I will give it to you if you cannot find a better one, but how about this?

http://www.planetsourcecode.com/xq/ASP/txtCodeId.1821/lngWId.1/qx/vb/scripts/ShowCode.htm
That one looks slow, not the implementation but the way it's designed. It appears to look thru a string after similar strings, and if you have a 24mb file this will mean a lot of lookbacks.
Avatar of tsa2

ASKER

Okay.. I think your code will do it. Thanks.
Avatar of tsa2

ASKER

I give you a 'B'. Not quite as fast as I expected, but MUCH faster. Thanks.
Is there any way to easily make this take longer but compress better?
tsa2: You could make it faster by converting some of the time-consuming code into machine-code. (i.e. the frequency counter and where it replaces the characters with the binary representation from the binary tree).

hess: I have a simple LZW compression on my harddrive I am working on, if you send me an email at mfitcom_suger@hotmail.com I'll send you a copy of it. Winzip uses a  combination of LZ77 and Huffman. And LZW is a variant of the same family compression (Lempel-Ziv). However it's only free to use in non-commercial software (patented algorithm).
Hum, my software is comercial, but i would be happy to alter the compression for better or worse to make it non standard... or what ever it takes... thanks, i'm sending you some mail...