// unzip is a helper function to unzip a file specified in src to path dest
unzip is a helper function to unzip a file specified in src to path dest
// unzip is a helper function to unzip a file specified in src to path dest
func unzip(src, dest string) (err error) {
	r, err := zip.OpenReader(src)
	if err != nil {
		return err
	}
	defer fs.CheckClose(r, &err)
	if err := os.MkdirAll(dest, 0755); err != nil {
		return err
	}
	extractAndWriteFile := func(f *zip.File) error {
		rc, err := f.Open()
		if err != nil {
			return err
		}
		defer fs.CheckClose(rc, &err)
		path := filepath.Join(dest, f.Name)
		if f.FileInfo().IsDir() {
			if err := os.MkdirAll(path, 0755); err != nil {
				return err
			}
		} else {
			if err := os.MkdirAll(filepath.Dir(path), 0755); err != nil {
				return err
			}
			f, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
			if err != nil {
				return err
			}
			defer fs.CheckClose(f, &err)
			_, err = io.Copy(f, rc)
			if err != nil {
				return err
			}
		}
		return nil
	}
	for _, f := range r.File {
		err := extractAndWriteFile(f)
		if err != nil {
			return err
		}
	}
	return nil
}
func unzip ( src , dest string ) ( err error ) { r , err := zip . OpenReader ( src ) if err != nil { return err } defer fs . CheckClose ( r , & err ) if err := os . MkdirAll ( dest , 0755 ) ; err != nil { return err } extractAndWriteFile := func ( f * zip . File ) error { rc , err := f . Open ( ) if err != nil { return err } defer fs . CheckClose ( rc , & err ) path := filepath . Join ( dest , f . Name ) if f . FileInfo ( ) . IsDir ( ) { if err := os . MkdirAll ( path , 0755 ) ; err != nil { return err } } else { if err := os . MkdirAll ( filepath . Dir ( path ) , 0755 ) ; err != nil { return err } f , err := os . OpenFile ( path , os . O_WRONLY | os . O_CREATE | os . O_TRUNC , 0644 ) if err != nil { return err } defer fs . CheckClose ( f , & err ) _ , err = io . Copy ( f , rc ) if err != nil { return err } } return nil } for _ , f := range r . File { err := extractAndWriteFile ( f ) if err != nil { return err } } return nil }
unzip is a helper function to unzip a file specified in src to path dest
unzip is a helper function to unzip a file specified in src to path dest
// Closure to address file descriptors issue with all the deferred .Close() methods