本文整理汇总了Golang中github.com/jhoonb/archivex.ZipFile.Create方法的典型用法代码示例。如果您正苦于以下问题:Golang ZipFile.Create方法的具体用法?Golang ZipFile.Create怎么用?Golang ZipFile.Create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/jhoonb/archivex.ZipFile
的用法示例。
在下文中一共展示了ZipFile.Create方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: backupFiles
func backupFiles(versionID string, wg *sync.WaitGroup) {
defer wg.Done()
if _, err := os.Stat(backupDir); err != nil {
if os.IsNotExist(err) {
makeBackupDir()
}
}
if debug {
fmt.Printf("backupFiles - %s\n", versionID)
}
log.Printf("backupFiles - %s\n", versionID)
fileName := fmt.Sprintf("%s%s%s_backup", backupDir, string(os.PathSeparator), versionID)
worldDir := fmt.Sprintf("%s", worldDir)
if _, err := os.Stat(backupDir); err != nil {
if os.IsNotExist(err) {
if debug {
fmt.Println("Nothing to backup right now.")
}
log.Println("Nothing to backup right now.")
} else {
zip := new(archivex.ZipFile)
zip.Create(fileName)
fmt.Printf("worldDir - %s\n", worldDir)
fmt.Printf("fileName - %s\n", fileName)
zip.AddAll(worldDir, true)
fmt.Printf("after addall\n")
zip.Close()
}
}
}
示例2: uploadProject
func uploadProject(appInfo *apps.AppInfo, repoPath string) (*api.File, error) {
// TODO: ignore files
fileDir, err := ioutil.TempDir("", "leanengine")
if err != nil {
return nil, err
}
filePath := filepath.Join(fileDir, "leanengine.zip")
println(filePath)
log.Println("压缩项目文件 ...")
zip := new(archivex.ZipFile)
func() {
defer zip.Close()
zip.Create(filePath)
zip.AddAll(repoPath, false)
}()
log.Println("上传项目文件 ...")
client := api.NewKeyAuthClient(appInfo.AppID, appInfo.MasterKey)
file, err := client.UploadFile(filePath)
utils.CheckError(err)
return file, nil
}
示例3: archive
func archive(dir string) {
zip := new(archivex.ZipFile)
pwd, err := os.Getwd()
check(err)
zip.Create(path.Join(pwd, "slackdump.zip"))
zip.AddAll(dir, true)
zip.Close()
}
示例4: archiveGame
func archiveGame(tempFile string, manifest *apipb.GameManifest) error {
archive := new(archivex.ZipFile)
err := archive.Create(tempFile)
if err != nil {
return err
}
p, _ := os.Getwd()
err = addAllFiles(archive, manifest, p, false)
if err != nil {
return err
}
return archive.Close()
}
示例5: archivePath
func archivePath(path string) (string, error) {
var zip archivex.ZipFile
var name string
var tempPath string
var err error
tempPath, err = ioutil.TempDir("", "")
if err != nil {
return "", err
}
name = filepath.Base(path)
tempPath = fmt.Sprintf("%s%s%s.zip", tempPath, string(os.PathSeparator), name)
zip.Create(tempPath)
zip.AddAll(path, false)
zip.Close()
return tempPath, nil
}
示例6: main
func main() {
//获取可执行文件所在的绝对路径
//不同于用户当前shell所在的目录
curDir, _ := osext.ExecutableFolder()
fmt.Println("current directory :", curDir)
//解析参数
version := flag.String("v", "0.0.1", "version number")
dir := flag.String("d", "res,src", "directory to walk")
server := flag.String("s", "http://192.168.0.134:8080/uploadfile", "web server address to upload")
flag.Parse()
//检查zip文件是否已存在
version_name := strings.Replace(*version, ".", "_", -1)
if exist(version_name + ".zip") {
panic(errors.New("already exist zip file : " + version_name + ".zip"))
}
fmt.Println("version number :", *version)
fmt.Println("directory to walk :", *dir)
fmt.Println("web server address to upload :", *server)
//md5校验和表
checksum_table := make(map[string]string)
f, err := os.OpenFile(path.Join(curDir, "CHECKSUM"), os.O_CREATE|os.O_APPEND|os.O_RDWR, 0660)
if err != nil {
panic(err)
}
//zip打包表
zip_table := make([]string, 0, 100)
defer func() {
json_data, err := json.Marshal(checksum_table)
if err != nil {
panic(err)
}
f.Close()
ioutil.WriteFile(path.Join(curDir, "CHECKSUM"), json_data, 0660)
if len(zip_table) != 0 {
//打包
zip := new(archivex.ZipFile)
zip.Create(path.Join(curDir, version_name+".zip"))
for _, v := range zip_table {
zip.AddFile(v)
}
zip.Close()
//上传
extraParams := map[string]string{
"title": "Zip File",
"author": "Jackie Sun",
"description": "A zip file that generated by assets-builder",
}
request, err := newfileUploadRequest(*server, extraParams, "file", path.Join(curDir, version_name+".zip"))
if err != nil {
log.Fatal(err)
}
client := &http.Client{}
resp, err := client.Do(request)
if err != nil {
log.Fatal(err)
} else {
body := &bytes.Buffer{}
_, err := body.ReadFrom(resp.Body)
if err != nil {
log.Fatal(err)
}
resp.Body.Close()
//fmt.Println(resp.StatusCode)
//fmt.Println(resp.Header)
fmt.Print(body)
}
} else {
fmt.Println("nothing to zip")
}
}()
//校验和文件源数据
checksum_data, err := ioutil.ReadAll(f)
if len(checksum_data) != 0 {
//fmt.Println("Unmarshal CHECKSUM")
err = json.Unmarshal(checksum_data, &checksum_table)
if err != nil {
panic(err)
}
//fmt.Printf("%#v\n", checksum_table)
}
for _, v := range strings.Split(*dir, ",") {
walkDir := path.Join(curDir, v)
//fmt.Println("---------- Walking directory :", walkDir, "----------")
filepath.Walk(walkDir,
func(path string, f os.FileInfo, err error) error {
if f == nil {
fmt.Println("FileInfo of path:", path, "is nil")
return err
}
if f.IsDir() {
return nil
}
//.........这里部分代码省略.........