コード例 #1
0
ファイル: zipper.go プロジェクト: rodney-vin/cli
func writeZipFile(dir string, targetFile *os.File) (err error) {
	isEmpty, err := fileutils.IsDirEmpty(dir)
	if err != nil {
		return
	}
	if isEmpty {
		err = errors.New("Directory is empty")
		return
	}

	writer := zip.NewWriter(targetFile)
	defer writer.Close()

	err = WalkAppFiles(dir, func(fileName string, fullPath string) (err error) {
		fileInfo, err := os.Stat(fullPath)
		if err != nil {
			return err
		}

		header, err := zip.FileInfoHeader(fileInfo)
		header.Name = filepath.ToSlash(fileName)
		if err != nil {
			return err
		}

		zipFilePart, err := writer.CreateHeader(header)
		err = fileutils.CopyPathToWriter(fullPath, zipFilePart)
		return
	})

	return
}
コード例 #2
0
ファイル: zipper.go プロジェクト: jalateras/cli
func writeZipFile(dir string, targetFile *os.File) (err error) {
	isEmpty, err := fileutils.IsDirEmpty(dir)
	if err != nil {
		return
	}
	if isEmpty {
		err = errors.New("Directory is empty")
		return
	}

	writer := zip.NewWriter(targetFile)
	defer writer.Close()

	err = walkAppFiles(dir, func(fileName string, fullPath string) (err error) {
		zipFilePart, err := writer.Create(fileName)
		err = fileutils.CopyPathToWriter(fullPath, zipFilePart)
		return
	})

	return
}