Sample code for 30+ languages & platforms
PowerBuilder

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

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

li_Success = 0

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

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_Bd = create oleobject
li_rc = loo_Bd.ConnectToNewObject("Chilkat.BinData")

loo_Json = create oleobject
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")

// Load a Gzip file into BinData:
li_Success = loo_Bd.LoadFile("example.txt.gz")
if li_Success = 0 then
    Write-Debug loo_Bd.LastErrorText
    destroy loo_Gzip
    destroy loo_Bd
    destroy loo_Json
    return
end if

// Get the metadata information from the in-memory Gzip data:
li_Success = loo_Gzip.GetGzipInfoBd(loo_Bd,loo_Json)
if li_Success = 0 then
    Write-Debug loo_Gzip.LastErrorText
    destroy loo_Gzip
    destroy loo_Bd
    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_Bd
destroy loo_Json