mirror of
https://github.com/avelino/awesome-go.git
synced 2024-11-14 16:42:23 +00:00
31 lines
427 B
Go
31 lines
427 B
Go
package main
|
|
|
|
import (
|
|
"compress/gzip"
|
|
"log"
|
|
"os"
|
|
)
|
|
|
|
func main() {
|
|
|
|
/*
|
|
Compress a File
|
|
*/
|
|
|
|
// Create .gz file to write to
|
|
outputFile, err := os.Create("test.txt.gz")
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
gzipWriter := gzip.NewWriter(outputFile)
|
|
defer gzipWriter.Close()
|
|
|
|
_, err = gzipWriter.Write([]byte("Gophers rule!\n"))
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
log.Println("Compressed data written to file.")
|
|
}
|