Sample code for 30+ languages & platforms
Visual Basic 6.0

Retrieve Metadata from Gzip Data in Memory (BinData)

This example demonstrates how to use the GetGzipInfoBd method to retrieve metadata from Gzip data stored in memory within a BinData object.

The Gzip data is first loaded into the BinData instance. The GetGzipInfoBd method then extracts any available metadata from the Gzip header, including the embedded filename, comment, and optional extra data.

The metadata is returned in a JsonObject. Because these fields are optional, the example checks for the existence of each JSON member using HasMember before retrieving its value.

Chilkat Visual Basic 6.0 Downloads

Visual Basic 6.0
Dim success As Long
success = 0

' This example demonstrates how to retrieve metadata from Gzip data
' stored in a BinData object.

Dim gzip As New ChilkatGzip
Dim bd As New ChilkatBinData
Dim json As New ChilkatJsonObject

' Load a Gzip file into BinData:
success = bd.LoadFile("example.txt.gz")
If (success = 0) Then
    Debug.Print bd.LastErrorText
    Exit Sub
End If

' Get the metadata information from the in-memory Gzip data:
success = gzip.GetGzipInfoBd(bd,json)
If (success = 0) Then
    Debug.Print gzip.LastErrorText
    Exit Sub
End If

' Output the JSON containing metadata:
Debug.Print "Gzip metadata JSON:"
Debug.Print json.Emit()

' Access individual fields only if they exist:

If (json.HasMember("filename") = 1) Then
    Dim filename As String
    filename = json.StringOf("filename")
    Debug.Print "Filename: " & filename
End If

If (json.HasMember("comment") = 1) Then
    Dim comment As String
    comment = json.StringOf("comment")
    Debug.Print "Comment: " & comment
End If

If (json.HasMember("extraData") = 1) Then
    Dim extraData As String
    extraData = json.StringOf("extraData")
    Debug.Print "ExtraData (Base64): " & extraData
End If