(Go) Unzip Text File to String
Demonstrates how to open a .zip and extract the 1st file (assuming it's a text file) to a string variable. Note: This example requires Chilkat v11.0.0 or greater.
success := false
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
zip := Zip_Ref.html">chilkat.NewZip()
success = zip.OpenZip("qa_data/zips/EC16100.zip")
if success == false {
fmt.Println(zip.LastErrorText())
zip.DisposeZip()
return
}
// Get the 1st file in the .zip
entry := ZipEntry_Ref.html">chilkat.NewZipEntry()
success = zip.EntryAt(0,entry)
if success == false {
fmt.Println(zip.LastErrorText())
zip.DisposeZip()
entry.DisposeZipEntry()
return
}
fileContents := entry.UnzipToString(0,"utf-8")
fmt.Println(*fileContents)
zip.DisposeZip()
entry.DisposeZipEntry()
|