代码拉取完成,页面将自动刷新
package serverHandler
import (
"archive/zip"
"io"
"net/http"
"os"
)
func writeZip(zw *zip.Writer, f *os.File, fInfo os.FileInfo, archivePath string) error {
if archivePath[0] == '/' {
archivePath = archivePath[1:]
}
if fInfo.IsDir() {
archivePath += "/"
}
var size int64
if !fInfo.IsDir() {
size = fInfo.Size()
}
w, err := zw.Create(archivePath)
if err != nil {
return err
}
if size == 0 || f == nil || fInfo.IsDir() {
return nil
}
_, err = io.Copy(w, f)
if err != nil {
return err
}
return nil
}
func (h *aliasHandler) zip(w http.ResponseWriter, r *http.Request, pageData *responseData) {
if !pageData.CanArchive {
w.WriteHeader(http.StatusBadRequest)
return
}
selections, ok := h.normalizeArchiveSelections(r)
if !ok {
return
}
zipWriter := zip.NewWriter(w)
defer func() {
err := zipWriter.Close()
h.logError(err)
}()
h.archive(
w,
r,
pageData,
selections,
".zip",
"application/zip",
func(f *os.File, fInfo os.FileInfo, relPath string) error {
return writeZip(zipWriter, f, fInfo, relPath)
},
)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。