LZMA Compression For VB6/VBA?
Looking to LZMA compress encrypted files in my Access 2000 application. Does anyone know the simplest way to do this in VB6/VBA or kno开发者_JS百科w of any source code?
You say you want to compress encrypted files? Compressing encrypted files usually doesn't result in much space saving as the encryption process scrambles the repeating structures that compression works on. So I assume you mean compress and encrypt files.
There is a 7-zip lzma SDK but you'd need to compile the code and work out how to turn it into a windows dll or something you can use.
I suggest you just push the task out to a command line i.e.
Sub test()
Dim ProgramTaskID As Double
ProgramTaskID = Shell("c:\compress.bat c:\source.txt c:\dest.zip", VbAppWinStyle.vbNormalFocus)
End Sub
You don't need to create a batch file for this, you could supply the command directly. The Shell function will return as soon as the program has launched, so you will need to wait and test for the output file to appear before you try and do anything with it.
7-zip is free and provides a command line syntax that you could use.
This one is not free and functionally might be an overkill (although you did mention encryption in your question ;-):
CryptoSys - Purchasing
CryptoSys - Features
Perhaps, one of the important traits of CryptoSys is that it supports several development languages/platforms, not just VB6 and VBA.
Similarly to Stepen Turner's answer, you could use xz.exe from the XZ Utils page (see Windows section).
The code would then look like this:
Sub LzmaCompression()
Dim ProgramTaskID As Double
ProgramTaskID = Shell("xz.exe --format=lzma test.txt", VbAppWinStyle.vbNormalFocus)
End Sub
精彩评论