Sample code for 30+ languages & platforms
PowerBuilder

Uncompress a Gzip File to a String

See more Gzip Examples

This example demonstrates how to use the UncompressFileToString method to decompress a Gzip (.gz) file that contains text and return the result as a string.

The method reads the compressed file, decompresses the data, and then converts the resulting bytes into a string using the specified character set (in this case, UTF-8).

It is important to specify the correct character set that matches the original encoding of the text. If the wrong character set is used, the resulting string may contain incorrect or unreadable characters.

This method is convenient when working with compressed text data that needs to be processed directly in memory without writing to a file.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
oleobject loo_Gzip
string ls_GzPath
string ls_Text

// This example demonstrates how to uncompress a Gzip (.gz) file
// that contains text and return the result as a string.

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

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

// Uncompress the file and interpret the result as UTF-8 text:
ls_Text = loo_Gzip.UncompressFileToString(ls_GzPath,"utf-8")
if loo_Gzip.LastMethodSuccess = 0 then
    Write-Debug loo_Gzip.LastErrorText
    destroy loo_Gzip
    return
end if

Write-Debug "Uncompressed text:"
Write-Debug ls_Text


destroy loo_Gzip