Exemplo n.º 1
0
func createFile(v *zip.File, dscDir string) error {
	v.Name = dscDir + v.Name
	info := v.FileInfo()
	if info.IsDir() {
		err := os.MkdirAll(v.Name, v.Mode())
		if err != nil {
			return errors.New(fmt.Sprintf("Error Create direcotry %s faild:\n%s\n", v.Name, err))
		}
		return nil
	}
	srcFile, err := v.Open()
	if err != nil {
		return errors.New(fmt.Sprintf("Error Read from zip faild:\n%s\n", err))
	}
	defer srcFile.Close()
	newFile, err := os.Create(v.Name)
	if err != nil {
		return errors.New(fmt.Sprintf("Error Create file faild:\n%s\n", err))
	}
	defer newFile.Close()
	io.Copy(newFile, srcFile)
	return nil
}