VBScript
VBScript
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 VBScript Downloads
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 from Gzip data
' stored in a BinData object.
set gzip = CreateObject("Chilkat.Gzip")
set bd = CreateObject("Chilkat.BinData")
set json = CreateObject("Chilkat.JsonObject")
' Load a Gzip file into BinData:
success = bd.LoadFile("example.txt.gz")
If (success = 0) Then
outFile.WriteLine(bd.LastErrorText)
WScript.Quit
End If
' Get the metadata information from the in-memory Gzip data:
success = gzip.GetGzipInfoBd(bd,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