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
+14.4k Golang : Find network of an IP address
+19.2k Golang : Check if directory exist and create if does not exist
+5.4k Golang : Return multiple values from function
+18.2k Golang : Get command line arguments
+6.9k Golang : How to solve "too many .rsrc sections" error?
+10k Golang : Read file and convert content to string
+7.5k Golang : How to stop user from directly running an executable file?
+15.2k Golang : How to check if IP address is in range
+4.4k Golang : Valued expressions and functions example
+4.9k HTTP common errors and their meaning explained
+14.6k Golang : Convert(cast) int to float example