|
-
Aug 21st, 2005, 01:04 PM
#1
Re: ZIP Compression Using Pure Visual Basic
Right. Believe it as you wish, for the sake of having a differing opinion. I haven't seen anything that proves against. "That's where the problem resides" doesn't really tell why there would be a problem or why VB couldn't do it.
Enjoy your "I won!" dance, won't comment on this any more.
The Proof: "This code can be used to create filetypes wich used Deflate as compression algo (ZIP,GZIP,CAB, etc.etc)" (mentioned earlier in this very thread)
Edit Fixed typo.
Last edited by Merri; Aug 21st, 2005 at 02:43 PM.
-
Aug 21st, 2005, 01:13 PM
#2
Re: ZIP Compression Using Pure Visual Basic
I would enjoy it more if someone proves me wrong, though.
-
Aug 21st, 2005, 03:34 PM
#3
Lively Member
Re: ZIP Compression Using Pure Visual Basic
 Originally Posted by RhinoBull
I would enjoy it more if someone proves me wrong, though.
I hope you will enjoy this 
1) Download the project from the link I posted.
2) Open cls_Zip.cls.
3) Add the following type:
Code:
Private Type Pack_Helper_Type
valid As Long
CRC32 As Long
USize As Long
CSize As Long
offset As Long
End Type
4) Overwrite the "pack" function with the following:
Code:
Public Function Pack(ZipName As String, files() As String, CompLevel As Integer) As Integer
Dim CentDat As Central_Header_Type
Dim helpers() As Pack_Helper_Type
Dim EndCentralSig As End_Header_Type
Dim fhIN As Integer, fhOUT As Integer
Dim i As Integer
Dim lngSig As Long, lngCenOff As Long
ReDim helpers(LBound(files) To UBound(files))
fhOUT = FreeFile
Open ZipName For Binary As #fhOUT
For i = LBound(files) To UBound(files)
If Not Trim$(files(i)) = vbNullString Then
helpers(i) = AppCompFile(fhOUT, files(i), CompLevel)
End If
Next
lngSig = &H2014B50
lngCenOff = Seek(fhOUT) - 1
For i = LBound(helpers) To UBound(helpers)
With CentDat
.CRC32 = helpers(i).CRC32
.CSize = helpers(i).CSize
.offset = helpers(i).offset
.USize = helpers(i).USize
.LenFname = Len(GetFile(files(i)))
.Method = CompLevel
.VerExt = 20
.VerMade = 20
End With
Put #fhOUT, , lngSig
Put #fhOUT, , CentDat
Put #fhOUT, , CStr(GetFile(files(i)))
Next
lngSig = &H6054B50
With EndCentralSig
.signature = lngSig
.Entries = UBound(files) - LBound(files) + 1
.TotEntr = .Entries
.CenOff = lngCenOff
.CenSize = Seek(fhOUT) - 1 - lngCenOff
End With
Put #fhOUT, , EndCentralSig
Close #fhOUT
End Function
Private Function AppCompFile(ByVal fh As Integer, ByVal file As String, ByVal level As Integer) As Pack_Helper_Type
'On Error GoTo OnError
Dim LocDat As Local_Header_Type
Dim fhIN As Integer
Dim btFile() As Byte
Dim lngSig As Long
AppCompFile.offset = Seek(fh) - 1
fhIN = FreeFile
Open file For Binary As #fhIN
ReDim btFile(LOF(fhIN) - 1) As Byte
Get #fhIN, , btFile
Close #fhIN
LocDat.USize = UBound(btFile) + 1
LocDat.CRC32 = CRC.CalcCRC32File(btFile)
Deflate btFile, level, False
With LocDat
.CSize = UBound(btFile) + 1
.LenFname = Len(GetFile(file))
.Method = level
.VerExt = 20
End With
lngSig = &H4034B50
Put #fh, , lngSig
Put #fh, , LocDat
Put #fh, , CStr(GetFile(file))
Put #fh, , btFile
With AppCompFile
.CRC32 = LocDat.CRC32
.CSize = LocDat.CSize
.USize = LocDat.USize
.valid = 1
End With
OnError:
End Function
Private Function GetFile(file As String) As String
GetFile = Mid$(file, InStrRev(file, "\") + 1)
End Function
Example on how to use this function:
Code:
Option Explicit
Dim p As New cls_Zip
Private Sub Form_Load()
Dim files(0) As String
files(0) = "C:\export.def"
p.Pack "C:\new.zip", files, 8
End Sub
I've done this in about 1 1/2 hours, so you can only add files to the root.
You want a feature, add it. 
/edit: Oups, I forgot, you have to add the Deflate module from DreamVB`s link.
Last edited by rm_03; Aug 21st, 2005 at 03:44 PM.
-
Aug 21st, 2005, 04:37 PM
#4
Re: ZIP Compression Using Pure Visual Basic
That proves nothing more than the fact that you can create files in VB.
-
Aug 22nd, 2005, 04:03 AM
#5
Lively Member
Re: ZIP Compression Using Pure Visual Basic
 Originally Posted by RhinoBull
That proves nothing more than the fact that you can create files in VB.
I don't get it...
1) The question was: code to compress a file with ZIP compression
2) You said: Can't be done in VB.
3) dreamvb posted a link to modules that show the Deflate/Inflate algorithms used in Zip files. Disproof of your statement.
4) You said you want a working example on how to create a Zip file with VB classic.
What you said with this is: You don't believe VB has arithmetic operators and can do file IO. The converse was proved just when VB was released some years ago.
5) I posted a working example on how to create the Zip file structure with compressed data in it.
6) You said: "This only proofs VB can do file IO".
Right... If VB creates a ZIP file, it's file IO.
If WinZip creates a ZIP file, it's a ZIP file.
This is ridiculous...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|