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
+11.3k Golang : Remove or trim extra comma from CSV
+7.1k Golang : Reverse text lines or flip line order example
+8.3k Golang : How to generate Code 39 barcode?
+25.9k PHP : Count number of JSON items/objects
+11.3k Golang : How to display image file or expose CSS, JS files from localhost?
+8.1k Golang : Play .WAV file from command line
+9.8k Golang : Sieve of Eratosthenes algorithm
+5k Golang : Detect variable or constant type
+20.9k Golang : Read directory content with filepath.Walk()
+3.8k Linux/MacOSX : How to symlink a file?
+3.8k JavaScript : Rounding number to decimal formats to display currency
+5.7k Golang : Warp text string by number of characters or runes example