Example #1
0
func unpackCompressedReader(targetDir string, tarFile io.Reader) error {
	tarFile, err := gzip.NewReader(tarFile)
	if err != nil {
		return errors.Annotate(err, "while uncompressing archive file")
	}
	err = tar.UntarFiles(tarFile, targetDir)
	return errors.Trace(err)
}
Example #2
0
// UnpackFilesBundle unpacks the archived files bundle into the targeted dir.
func (ws *ArchiveWorkspace) UnpackFilesBundle(targetRoot string) error {
	tarFile, err := os.Open(ws.FilesBundle)
	if err != nil {
		return errors.Trace(err)
	}
	defer tarFile.Close()

	err = tar.UntarFiles(tarFile, targetRoot)
	return errors.Trace(err)
}
Example #3
0
// Extract unpacks a tar or zip archive to outputDir (defaults to working directory).
// Supported extension: tar, zip
// Defaults:
// 		- outputDir	os.Getwd()
// TODO:
//		- ignore file extensions, try to parse headers
func Extract(filename, outputDir string) error {
	if _, err := os.Stat(filename); err != nil {
		return fmt.Errorf("couldn't access file %s: %+v", filename, err)
	}
	if outputDir == "" {
		outputDir, _ = os.Getwd()
	}
	if strings.HasSuffix(filename, ".tar") {
		r, err := os.Open(filename)
		if err != nil {
			return fmt.Errorf("couldn't open file %s: %+v", filename, err)
		}
		return tar.UntarFiles(r, outputDir)
	}
	if strings.HasSuffix(filename, ".zip") {
		r, err := zip.OpenReader(filename)
		if err != nil {
			return fmt.Errorf("couldn't open archive %s: %+v", filename, err)
		}
		return jzip.ExtractAll(&r.Reader, outputDir)
	}
	return fmt.Errorf("only supporting tar and zip files at the moment")
}