Lianja
Lianja
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 Lianja Downloads
llSuccess = .F.
// This example demonstrates how to retrieve metadata embedded in a Gzip file.
loGzip = createobject("CkGzip")
loJson = createobject("CkJsonObject")
// The Gzip file to examine:
lcGzPath = "example.txt.gz"
// Get the metadata information:
llSuccess = loGzip.GetGzipInfo(lcGzPath,loJson)
if (llSuccess = .F.) then
? loGzip.LastErrorText
release loGzip
release loJson
return
endif
// Output the JSON containing metadata:
? "Gzip metadata JSON:"
? loJson.Emit()
// Access individual fields only if they exist:
if (loJson.HasMember("filename") = .T.) then
lcFilename = loJson.StringOf("filename")
? "Filename: " + lcFilename
endif
if (loJson.HasMember("comment") = .T.) then
lcComment = loJson.StringOf("comment")
? "Comment: " + lcComment
endif
if (loJson.HasMember("extraData") = .T.) then
lcExtraData = loJson.StringOf("extraData")
? "ExtraData (Base64): " + lcExtraData
endif
release loGzip
release loJson