pupate

No description provided
git clone https://git.woozle.org/neale/pupate.git

pupate / examples
Neale Pickett  ·  2024-12-20

main.go

 1package examples
 2
 3import (
 4	"archive/zip"
 5	"bytes"
 6	"embed"
 7	"io"
 8)
 9
10// FS contains built-in examples.
11//
12//go:embed *
13var FS embed.FS
14
15// zbuf is the cached ZIP archive of FS.
16var zbuf []byte
17
18// ZipFile returns a ZIP archive of the built-in examples.
19func ZipFile() (io.ReadSeeker) {
20	if zbuf == nil {
21		buf := new(bytes.Buffer)
22		w := zip.NewWriter(buf)
23		if err := w.AddFS(FS); err != nil {
24			// My read of embed.go leads me to believe this will never happen.
25			panic(err)
26		}
27		w.Close()
28		zbuf = buf.Bytes()
29	}
30
31	return bytes.NewReader(zbuf)
32}