Read Gzip file content with golang

With one of my recent tasks, I had to read Gzipped JSON files from a directory.

This proved to be pretty easy (as a lot of things with Go are), but I thought
it’s pretty useful to blog about it since many people likely need this

package main

import (

func main() {
	filename := "your-file-name.gz"
	file, err := os.Open(filename)

	if err != nil {

	gz, err := gzip.NewReader(file)

	if err != nil {

	defer file.Close()
	defer gz.Close()

	scanner := bufio.NewScanner(gz)

From there, you can do with scanner what ever you want, I needed to read the
lines one by one in order to parse each of the lines as JSON but obviously, you
can do whatever you want with it.

Keep Hacking!