"hash"
"hash/crc32"
"io"
+ "io/fs"
"strings"
"unicode/utf8"
)
w.compressors[method] = comp
}
+// AddFS adds the files from fs.FS to the archive.
+// It walks the directory tree starting at the root of the filesystem
+// adding each file to the zip using deflate while maintaining the directory structure.
+func (w *Writer) AddFS(fsys fs.FS) error {
+ return fs.WalkDir(fsys, ".", func(name string, d fs.DirEntry, err error) error {
+ if err != nil {
+ return err
+ }
+ if d.IsDir() {
+ return nil
+ }
+ info, err := d.Info()
+ if err != nil {
+ return err
+ }
+ h, err := FileInfoHeader(info)
+ if err != nil {
+ return err
+ }
+ h.Name = name
+ h.Method = Deflate
+ fw, err := w.CreateHeader(h)
+ if err != nil {
+ return err
+ }
+ f, err := fsys.Open(name)
+ if err != nil {
+ return err
+ }
+ defer f.Close()
+ _, err = io.Copy(fw, f)
+ return err
+ })
+}
+
func (w *Writer) compressor(method uint16) Compressor {
comp := w.compressors[method]
if comp == nil {