January 2018
Intermediate to advanced
340 pages
8h 6m
English
The following example demonstrates how to uncompress a file using the gzip algorithm:
// This example uses gzip but standard library also // supports zlib, bz2, flate, and lzw package main import ( "compress/gzip" "io" "log" "os" ) func main() { // Open gzip file that we want to uncompress // The file is a reader, but we could use any // data source. It is common for web servers // to return gzipped contents to save bandwidth // and in that case the data is not in a file // on the file system but is in a memory buffer gzipFile, err := os.Open("test.txt.gz") if err != nil { log.Fatal(err) } // Create a gzip reader on top of the file reader // Again, it could be any type reader though gzipReader, err := gzip.NewReader(gzipFile) ...Read now
Unlock full access