LoginSignup
2
2

More than 5 years have passed since last update.

Goでzipファイルつくる

Posted at

package main

import (
    "archive/zip"
    "os"
    "path"
)

func main() {
    // 生成するzipファイル
    file, _ := os.Create("foo.zip")

    // zipファイルを閉じる
    defer file.Close()

    // zipファイルにzip.NewWriterで書けるようにする
    // つまり w が色々な情報を持っている
    w := zip.NewWriter(file)

    // unzipした時のファイル名
    f, _ := w.Create(path.Base("foo.txt"))

    // 書き込む内容
    _, _ = f.Write([]byte("hogehoge"))

    _ = w.Close()
}
2
2
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
2
2