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()
}
More than 5 years have passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme