0
1

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 5 years have passed since last update.

agoutiで撮ったスクリーンショットをzipする【Go】

Posted at

概要

agouti + phantomjsでスクリーンショットを撮ったのち、ローカルに保存、zipにまとめる
zipはarchive/zipパッケージを使う

やり方

filename := "/path/to/file/screenshot.jpg"
page.Screenshot(filename)

dest, err := os.Create("screenshot.zip") //zip完成
if err != nil {
    log.Fatal(err)
}

zipWriter := zip.NewWriter(dest)
defer zipWriter.Close()

file, err := os.Open(filename)
if err != nil {
    log.Fatal(err)
}
defer file.Close()

w, err := zipWriter.Create(filename)//zip内にできるファイルのwriterを返す
if err != nil {
    log.Fatal(err)
}

_, err = io.Copy(w, file)//fileの内容をfilenameに書き込む
if err != nil {
    log.Fatal(err)
}


何か間違いがあればご指摘ください

0
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?