Golang compress/bzip2.NewReader() function example
package compress/bzip2
Golang compress/bzip2.NewReader() function usage example. For decompressing .bz2
file.
package main
import (
"compress/bzip2"
"fmt"
"io"
"os"
)
func main() {
inputFile, err := os.Open("file.txt.bz2")
if err != nil {
fmt.Println(err)
os.Exit(1)
}
defer inputFile.Close()
outputFile, err := os.Create("file.txt")
if err != nil {
fmt.Println(err)
os.Exit(1)
}
defer outputFile.Close()
bzip2reader := bzip2.NewReader(inputFile)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
io.Copy(outputFile, bzip2reader)
}
Reference :
Advertisement
Something interesting
Tutorials
+16.4k CodeIgniter/PHP : Create directory if does not exist example
+7k Golang : Levenshtein distance example
+7.1k Nginx : How to block user agent ?
+9.7k Random number generation with crypto/rand in Go
+7.9k Swift : Convert (cast) String to Float
+14.4k Golang : How to filter a map's elements for faster lookup
+4.7k PHP : Extract part of a string starting from the middle
+9.6k Javascript : Read/parse JSON data from HTTP response
+10.5k Golang : Select region of interest with mouse click and crop from image
+5.7k Golang : Error handling methods
+18.4k Golang : Logging with logrus
+23.1k Golang : Randomly pick an item from a slice/array example