0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Go言語でgzipファイルを解凍したい

0
Posted at

Go言語では標準ライブラリだけで、gzipファイルを解凍することができます。

以下は./access.log.gzファイルを解凍し、./access.logに保存するサンプルコードです。

srcPath := "./access.log.gz"
dstPath := "./access.log"

src, err := os.Open(srcPath)
if err != nil {
	panic(err)
}
defer src.Close()

gr, err := gzip.NewReader(src)
if err != nil {
	panic(err)
}
defer gr.Close()

dst, err := os.Create(dstPath)
if err != nil {
	panic(err)
}
defer dst.Close()

if _, err := io.Copy(dst, gr); err != nil {
	panic(err)
}

環境情報

$ go version
go version go1.19 linux/amd64
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?