Sample code for 30+ languages & platforms
VBScript

Retrieve Metadata from a Gzip File

See more Gzip Examples

This example demonstrates how to use the GetGzipInfo method to retrieve metadata embedded within a Gzip file.

The method reads the Gzip header and extracts any available metadata, including the embedded filename, comment, and optional extra data. The extracted information 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. This avoids attempting to access values that may not be present.

Chilkat VBScript Downloads

VBScript
Dim fso, outFile
Set fso = CreateObject("Scripting.FileSystemObject")
'Create a Unicode (utf-16) output text file.
Set outFile = fso.CreateTextFile("output.txt", True, True)

success = 0

' This example demonstrates how to retrieve metadata embedded in a Gzip file.

set gzip = CreateObject("Chilkat.Gzip")
set json = CreateObject("Chilkat.JsonObject")

' The Gzip file to examine:
gzPath = "example.txt.gz"

' Get the metadata information:
success = gzip.GetGzipInfo(gzPath,json)
If (success = 0) Then
    outFile.WriteLine(gzip.LastErrorText)
    WScript.Quit
End If

' Output the JSON containing metadata:
outFile.WriteLine("Gzip metadata JSON:")
outFile.WriteLine(json.Emit())

' Access individual fields only if they exist:

If (json.HasMember("filename") = 1) Then
    filename = json.StringOf("filename")
    outFile.WriteLine("Filename: " & filename)
End If

If (json.HasMember("comment") = 1) Then
    comment = json.StringOf("comment")
    outFile.WriteLine("Comment: " & comment)
End If

If (json.HasMember("extraData") = 1) Then
    extraData = json.StringOf("extraData")
    outFile.WriteLine("ExtraData (Base64): " & extraData)
End If


outFile.Close