Die Community zu .NET und Classic VB.
Menü

ZIP

 von 

Übersicht 

Beschreibung

Archivformat von PKWARE.

Allgemeiner Aufbau  

Header
Header zpHeader
Daten / Informationen zu den Daten
Lokaler Dateiheader [1] zpLocalHeader
Daten [1]
Informationen zu den Daten [1] zpDataDescriptor
.
.
.
Lokaler Dateiheader [n] zpLocalHeader
Daten [n]
Informationen zu den Daten [n] zpDataDescriptor
Header [n] zpHeader

Weitere Informationen  

zpHeader
Type zpHeader
  LocalFileHeader As String * 4
End Type
zpLocalHeader
Type zpLocalHeader
 Version As Integer
 GeneralPurposeBitFlag As Integer
 CompressionMethod As Integer
 LastModFileTime As Integer
 LastModFileDate As Integer
 CRC32 As Long
 CompressedSize As Long
 UncompressedSize As Long
 FileNameLength As Integer
 ExtraFieldLength As Integer
End Type
zpDataDescriptor
Type zpDataDescriptor
 CRC32 As Long
 CompressedSize As Long
 UncompressedSize As Long
End Type

Beispiel  

Option Explicit

Private Type zpHeader
    LocalFileHeader As String * 4
End Type

Private Type zpLocalHeader
    Version As Integer
    GeneralPurposeBitFlag As Integer
    CompressionMethod As Integer
    LastModFileTime As Integer
    LastModFileDate As Integer
    CRC32 As Long
    CompressedSize As Long
    UncompressedSize As Long
    FileNameLength As Integer
    ExtraFieldLength As Integer
End Type

Private Type zpDataDescriptor
    CRC32 As Long
    CompressedSize As Long
    UncompressedSize As Long
End Type

Dim zpCached As String
Dim zpFileAnz As Long
Dim zpEntries(10000) As String
Dim zpFileLen(10000) As Long
Dim zpFilePos(10000) As Long

'---------------------------------
'Lädt alle Infos in den Speicher
'---------------------------------

Public Sub CacheZIP(ZIPFile As String)
    Dim Puffer As String
    Dim lpFileName As String
    Dim zpHead As zpHeader
    Dim zpLocalHead As zpLocalHeader
    Dim zpLen  As Long, zpFile As Integer
    zpLen = FileLen(ZIPFile)
    zpFile = FreeFile
    Open ZIPFile For Binary As zpFile
        Get zpFile, 1, zpHead
        Do While zpHead.LocalFileHeader = "PK" & Chr(3) & Chr(4)
            Get zpFile, , zpLocalHead
            Puffer = Space(zpLocalHead.FileNameLength)
            Get zpFile, , Puffer
            lpFileName = Puffer
            Puffer = Space(zpLocalHead.ExtraFieldLength)
            Get zpFile, , Puffer
            If Not zpLocalHead.CompressedSize = 0 Then
                zpFilePos(zpFileAnz) = Seek(zpFile)
                zpFileLen(zpFileAnz) = zpLocalHead.CompressedSize
                zpEntries(zpFileAnz) = lpFileName
                zpFileAnz = zpFileAnz + 1
            End If
            Seek zpFile, Seek(zpFile) + zpLocalHead.CompressedSize
            Get zpFile, , zpHead
        Loop
    Close zpFile
    zpCached = ZIPFile
End Sub

'---------------------------------------
'Gibt die Anzahl der Dateien im Archiv
'zurück
'---------------------------------------
Public Function GetFileCount(ZIPFile As String)
    If Not zpCached = ZIPFile Then
        CacheZIP ZIPFile
    End If
    GetFileCount = zpFileAnz
End Function

'----------------------------------------
'Gibt den Dateinamen der Datei "FileIndx"
'zurück
'----------------------------------------
Public Function GetEntry(ZIPFile As String, _
    FileIndx As Integer) As String
    If Not zpCached = ZIPFile Then
        CacheZIP ZIPFile
    End If
    GetEntry = zpEntries(FileIndx)
End Function