Sample code for 30+ languages & platforms
PowerBuilder

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 PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Gzip
oleobject loo_Json
string ls_GzPath
string ls_Filename
string ls_Comment
string ls_ExtraData

li_Success = 0

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

loo_Gzip = create oleobject
li_rc = loo_Gzip.ConnectToNewObject("Chilkat.Gzip")
if li_rc < 0 then
    destroy loo_Gzip
    MessageBox("Error","Connecting to COM object failed")
    return
end if
loo_Json = create oleobject
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")

// The Gzip file to examine:
ls_GzPath = "example.txt.gz"

// Get the metadata information:
li_Success = loo_Gzip.GetGzipInfo(ls_GzPath,loo_Json)
if li_Success = 0 then
    Write-Debug loo_Gzip.LastErrorText
    destroy loo_Gzip
    destroy loo_Json
    return
end if

// Output the JSON containing metadata:
Write-Debug "Gzip metadata JSON:"
Write-Debug loo_Json.Emit()

// Access individual fields only if they exist:

if loo_Json.HasMember("filename") = 1 then
    ls_Filename = loo_Json.StringOf("filename")
    Write-Debug "Filename: " + ls_Filename
end if

if loo_Json.HasMember("comment") = 1 then
    ls_Comment = loo_Json.StringOf("comment")
    Write-Debug "Comment: " + ls_Comment
end if

if loo_Json.HasMember("extraData") = 1 then
    ls_ExtraData = loo_Json.StringOf("extraData")
    Write-Debug "ExtraData (Base64): " + ls_ExtraData
end if



destroy loo_Gzip
destroy loo_Json