Last active
July 20, 2016 07:36
-
-
Save kenjiskywalker/d02839e409f20a6f51dadf65e1dde603 to your computer and use it in GitHub Desktop.
Goのzipのメモ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"archive/zip" | |
"os" | |
"path" | |
"github.com/k0kubun/pp" | |
) | |
func main() { | |
// 生成するzipファイル | |
file, _ := os.Create("foo.zip") | |
// zipファイルを閉じる | |
defer file.Close() | |
// zipファイルにzip.NewWriterで書けるようにする | |
// つまり w が色々な情報を持っている | |
w := zip.NewWriter(file) | |
// wの中見てみる | |
pp.Print(*w) | |
// zip.Writer{ | |
// cw: &zip.countWriter{ | |
// w: &bufio.Writer{ | |
// err: nil, | |
// buf: []uint8{...}, | |
// n: 0, | |
// wr: &os.File{ | |
// file: &os.file{ | |
// fd: 3, | |
// name: "foo.zip", | |
// dirinfo: (*os.dirInfo)(nil), | |
// }, | |
// }, | |
// }, | |
// count: 0, | |
// }, | |
// dir: []*zip.header{}, | |
// last: (*zip.fileWriter)(nil), | |
// closed: false, | |
// compressors: map[uint16]zip.Compressor{}, | |
// } | |
// unzipした時のファイル名 | |
f, _ := w.Create(path.Base("foo.txt")) | |
// 書き込む内容 | |
_, _ = f.Write([]byte("hogehoge")) | |
_ = w.Close() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment