Visual FoxPro
Visual FoxPro
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 Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loGzip
LOCAL loJson
LOCAL lcGzPath
LOCAL lcFilename
LOCAL lcComment
LOCAL lcExtraData
lnSuccess = 0
* This example demonstrates how to retrieve metadata embedded in a Gzip file.
loGzip = CreateObject('Chilkat.Gzip')
loJson = CreateObject('Chilkat.JsonObject')
* The Gzip file to examine:
lcGzPath = "example.txt.gz"
* Get the metadata information:
lnSuccess = loGzip.GetGzipInfo(lcGzPath,loJson)
IF (lnSuccess = 0) THEN
? loGzip.LastErrorText
RELEASE loGzip
RELEASE loJson
CANCEL
ENDIF
* Output the JSON containing metadata:
? "Gzip metadata JSON:"
? loJson.Emit()
* Access individual fields only if they exist:
IF (loJson.HasMember("filename") = 1) THEN
lcFilename = loJson.StringOf("filename")
? "Filename: " + lcFilename
ENDIF
IF (loJson.HasMember("comment") = 1) THEN
lcComment = loJson.StringOf("comment")
? "Comment: " + lcComment
ENDIF
IF (loJson.HasMember("extraData") = 1) THEN
lcExtraData = loJson.StringOf("extraData")
? "ExtraData (Base64): " + lcExtraData
ENDIF
RELEASE loGzip
RELEASE loJson