Sample code for 30+ languages & platforms
DataFlex

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

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoGzip
    Variant vBd
    Handle hoBd
    Variant vJson
    Handle hoJson
    String sFilename
    String sComment
    String sExtraData
    String sTemp1
    Boolean bTemp1

    Move False To iSuccess

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

    Get Create (RefClass(cComChilkatGzip)) To hoGzip
    If (Not(IsComObjectCreated(hoGzip))) Begin
        Send CreateComObject of hoGzip
    End
    Get Create (RefClass(cComChilkatBinData)) To hoBd
    If (Not(IsComObjectCreated(hoBd))) Begin
        Send CreateComObject of hoBd
    End
    Get Create (RefClass(cComChilkatJsonObject)) To hoJson
    If (Not(IsComObjectCreated(hoJson))) Begin
        Send CreateComObject of hoJson
    End

    // Load a Gzip file into BinData:
    Get ComLoadFile Of hoBd "example.txt.gz" To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoBd To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    // Get the metadata information from the in-memory Gzip data:
    Get pvComObject of hoBd to vBd
    Get pvComObject of hoJson to vJson
    Get ComGetGzipInfoBd Of hoGzip vBd vJson To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoGzip To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    // Output the JSON containing metadata:
    Showln "Gzip metadata JSON:"
    Get ComEmit Of hoJson To sTemp1
    Showln sTemp1

    // Access individual fields only if they exist:

    Get ComHasMember Of hoJson "filename" To bTemp1
    If (bTemp1 = True) Begin
        Get ComStringOf Of hoJson "filename" To sFilename
        Showln "Filename: " sFilename
    End

    Get ComHasMember Of hoJson "comment" To bTemp1
    If (bTemp1 = True) Begin
        Get ComStringOf Of hoJson "comment" To sComment
        Showln "Comment: " sComment
    End

    Get ComHasMember Of hoJson "extraData" To bTemp1
    If (bTemp1 = True) Begin
        Get ComStringOf Of hoJson "extraData" To sExtraData
        Showln "ExtraData (Base64): " sExtraData
    End



End_Procedure