// Extract bzip2
547715
func Extract(src string, dest string) error {
	file, err := os.Open(src)

	if err != nil {
		return err
	}

	defer file.Close()

	return tar.Extract(bzip2.NewReader(file), dest)
}
277167
func PackBytesGzip(box string, name string, bb []byte) error {
	// TODO: this function never did what it was supposed to do!
	PackBytes(box, name, bb)
	return nil
}
628637
func ExtractHeader(header string, resp *http.Response) []string {
	if resp != nil && resp.Header != nil {
		return resp.Header[http.CanonicalHeaderKey(header)]
	}
	return nil
}
515169
func (z *ZipArchive) extractFile(f *File) error {
	if !z.isHasWriter {
		for _, zf := range z.ReadCloser.File {
			if f.Name == zf.Name {
				return extractFile(zf, path.Dir(f.tmpPath))
			}
		}
	}
	return cae.Copy(f.tmpPath, f.absPath)
}
446966
func ExtractExtraHeaders(opts ...interface{}) *opt.ExtraHeadersOption {
	merged := make(map[string]string)

	for _, o := range opts {
		if v, ok := o.(*opt.ExtraHeadersOption); ok {
			for key, value := range v.Get() {
				merged[key] = value
			}
		}
	}

	if len(merged) == 0 {
		return nil
	}

	return opt.ExtraHeaders(merged)
}
111100
func Zip(slice1 interface{}, slice2 interface{}) []Tuple {
	inValue1 := reflect.ValueOf(slice1)
	inValue2 := reflect.ValueOf(slice2)
	kind1 := inValue1.Type().Kind()
	kind2 := inValue2.Type().Kind()

	result := []Tuple{}
	for _, kind := range []reflect.Kind{kind1, kind2} {
		if kind != reflect.Slice && kind != reflect.Array {
			return result
		}
	}

	var minLength int
	length1 := inValue1.Len()
	length2 := inValue2.Len()
	if length1 <= length2 {
		minLength = length1
	} else {
		minLength = length2
	}

	for i := 0; i < minLength; i++ {
		newTuple := Tuple{
			Element1: inValue1.Index(i).Interface(),
			Element2: inValue2.Index(i).Interface(),
		}
		result = append(result, newTuple)
	}
	return result
}
1254683
func (c FSIndexBlobs) Get(name string, blobID string, digestString string) (string, error) {
	dstPath, err := c.blobPath(digestString)
	if err != nil {
		return "", err
	}

	if c.fs.FileExists(dstPath) {
		digest, err := boshcrypto.ParseMultipleDigest(digestString)
		if err != nil {
			return "", err
		}

		err = digest.VerifyFilePath(dstPath, c.fs)
		if err != nil {
			errMsg := "Local copy ('%s') of blob '%s' digest verification error"
			return "", bosherr.WrapErrorf(err, errMsg, dstPath, blobID)
		}

		return dstPath, nil
	}

	if c.blobstore != nil && len(blobID) > 0 {
		desc := fmt.Sprintf("sha1=%s", digestString)

		digest, err := boshcrypto.ParseMultipleDigest(digestString)
		if err != nil {
			return "", bosherr.WrapErrorf(err, "Downloading blob '%s' with digest '%s'", blobID, digestString)
		}

		c.reporter.IndexEntryDownloadStarted(name, desc)

		path, err := c.blobstore.Get(blobID, digest)
		if err != nil {
			c.reporter.IndexEntryDownloadFinished(name, desc, err)
			return "", bosherr.WrapErrorf(err, "Downloading blob '%s' with digest string '%s'", blobID, digestString)
		}

		err = boshfu.NewFileMover(c.fs).Move(path, dstPath)
		if err != nil {
			c.reporter.IndexEntryDownloadFinished(name, desc, err)
			return "", bosherr.WrapErrorf(err, "Moving blob '%s' into cache", blobID)
		}

		c.reporter.IndexEntryDownloadFinished(name, desc, nil)

		return dstPath, nil
	}

	if len(blobID) == 0 {
		return "", bosherr.Errorf("Cannot find blob named '%s' with SHA1 '%s'", name, digestString)
	}

	return "", bosherr.Errorf("Cannot find blob '%s' with SHA1 '%s'", blobID, digestString)
}
1162815
func (p *WebHookPlugin) Extract(buildCfg *buildv1.BuildConfig, trigger *buildv1.WebHookTrigger, req *http.Request) (revision *buildv1.SourceRevision, envvars []corev1.EnvVar, dockerStrategyOptions *buildv1.DockerStrategyOptions, proceed bool, err error) {
	klog.V(4).Infof("Verifying build request for BuildConfig %s/%s", buildCfg.Namespace, buildCfg.Name)
	if err = verifyRequest(req); err != nil {
		return revision, envvars, dockerStrategyOptions, false, err
	}

	method := getEvent(req.Header)
	branch := ""
	switch method {
	// https://confluence.atlassian.com/bitbucket/event-payloads-740262817.html
	case "repo:push":
		branch, revision, err = getInfoFromEvent(req.Body)
		if err != nil {
			return revision, envvars, dockerStrategyOptions, false, errors.NewBadRequest(err.Error())
		}

	// https://confluence.atlassian.com/bitbucketserver/event-payload-938025882.html
	case "repo:refs_changed":
		branch, revision, err = getInfoFromEvent54(req.Body)
		if err != nil {
			return revision, envvars, dockerStrategyOptions, false, errors.NewBadRequest(err.Error())
		}
	default:
		return revision, envvars, dockerStrategyOptions, false, errors.NewBadRequest(fmt.Sprintf("Unknown Bitbucket X-Event-Key %s", method))
	}

	if !webhook.GitRefMatches(branch, webhook.DefaultConfigRef, &buildCfg.Spec.Source) {
		klog.V(2).Infof("Skipping build for BuildConfig %s/%s.  Branch reference '%s' does not match configuration", buildCfg.Namespace, buildCfg.Name, branch)
		return revision, envvars, dockerStrategyOptions, false, err
	}

	return revision, envvars, dockerStrategyOptions, true, err
}
1211409
func ExtractCompressedPublicKey(pm string) string {
	key := ExtractKeyFromPem(pm)
	pub := key.PubKey()
	comp := pub.SerializeCompressed()
	hexb := hex.EncodeToString(comp)
	return hexb
}
1171423
func extract(buf []byte, name string) []byte {
	extractRE := regexp.MustCompile(`\s+` + name + `.+?{`)
	buf = buf[extractRE.FindIndex(buf)[0]:]
	return buf[:endRE.FindIndex(buf)[1]]
}
522711
func (i *Image) Extract(top, left, width, height int) ([]byte, error) {
	options := Options{
		Top:        top,
		Left:       left,
		AreaWidth:  width,
		AreaHeight: height,
	}

	if top == 0 && left == 0 {
		options.Top = -1
	}

	return i.Process(options)
}
1172784
func ExtractQuery(opts ...interface{}) *opt.QueryOption {
	for _, o := range opts {
		if v, ok := o.(*opt.QueryOption); ok {
			return v
		}
	}
	return nil
}
771251
func Gzipper(gzipPath string) (*bytes.Buffer, error) {
	f, err := os.Open(gzipPath)
	if err != nil {
		return nil, err
	}
	defer f.Close()

	// Gzip the binary data and toss it in a buffer.
	buffer := bytes.NewBuffer(nil)
	gzipData := gzip.NewWriter(buffer)
	gzipData.Header.Name = filepath.Base(gzipPath)
	gzipData.Header.ModTime = time.Now()
	if _, err := io.Copy(gzipData, f); err != nil {
		return nil, err
	}
	if err := gzipData.Close(); err != nil {
		return nil, err
	}
	return buffer, nil
}
578857
func (tbz2 *TarBz2) Extract(source, target, destination string) error {
	tbz2.wrapReader()
	return tbz2.Tar.Extract(source, target, destination)
}
973223
func (r *tarReader) Extract(fileName string, noOverride bool) error {
	fileInfo, err := os.Lstat(fileName)
	if err != nil && !os.IsNotExist(err) {
		return err
	}

	// If the `fileName` already exists on disk and it is a file
	// we try to delete it in order to create a new one unless
	// `noOverride` is set to true
	if err == nil && !fileInfo.IsDir() {
		if noOverride {
			return nil
		}

		if err := os.Remove(fileName); err != nil {
			return err
		}
	}

	// header.Mode is in linux format, we have to convert it to os.FileMode
	// to be compatible to other platforms.
	headerInfo := r.header.FileInfo()

	switch r.header.Typeflag {
	case tar.TypeDir:
		if err := os.Mkdir(fileName, headerInfo.Mode()); err != nil && !os.IsExist(err) {
			return err
		}
	case tar.TypeReg, tar.TypeRegA:
		if err := createFile(fileName, headerInfo.Mode(), r.reader); err != nil {
			return err
		}
	case tar.TypeSymlink:
		if err := os.Symlink(r.header.Linkname, fileName); err != nil {
			return err
		}
	default:
		return fmt.Errorf("Unhandled tar header type %d", r.header.Typeflag)
	}

	return nil
}
867407
func (g *TarGzExtractor) Extract(buffer *bytes.Buffer, targetDir string) error {
	uncompressedStream, err := gzip.NewReader(buffer)
	if err != nil {
		return err
	}

	tarReader := tar.NewReader(uncompressedStream)

	os.MkdirAll(targetDir, 0755)

	for true {
		header, err := tarReader.Next()

		if err == io.EOF {
			break
		}

		if err != nil {
			return err
		}

		path, err := fp.SecureJoin(targetDir, header.Name)
		if err != nil {
			return err
		}

		switch header.Typeflag {
		case tar.TypeDir:
			if err := os.Mkdir(path, 0755); err != nil {
				return err
			}
		case tar.TypeReg:
			outFile, err := os.Create(path)
			if err != nil {
				return err
			}
			if _, err := io.Copy(outFile, tarReader); err != nil {
				outFile.Close()
				return err
			}
			outFile.Close()
		default:
			return fmt.Errorf("unknown type: %b in %s", header.Typeflag, header.Name)
		}
	}

	return nil

}
937033
func (p *WebHookPlugin) Extract(buildCfg *buildv1.BuildConfig, trigger *buildv1.WebHookTrigger, req *http.Request) (revision *buildv1.SourceRevision, envvars []corev1.EnvVar, dockerStrategyOptions *buildv1.DockerStrategyOptions, proceed bool, err error) {
	klog.V(4).Infof("Verifying build request for BuildConfig %s/%s", buildCfg.Namespace, buildCfg.Name)
	if err = verifyRequest(req); err != nil {
		return revision, envvars, dockerStrategyOptions, false, err
	}

	contentType := req.Header.Get("Content-Type")
	if len(contentType) != 0 {
		contentType, _, err = mime.ParseMediaType(contentType)
		if err != nil {
			return revision, envvars, dockerStrategyOptions, false, errors.NewBadRequest(fmt.Sprintf("error parsing Content-Type: %s", err))
		}
	}

	if req.Body == nil {
		return revision, envvars, dockerStrategyOptions, true, nil
	}

	if contentType != "application/json" && contentType != "application/yaml" {
		warning := webhook.NewWarning("invalid Content-Type on payload, ignoring payload and continuing with build")
		return revision, envvars, dockerStrategyOptions, true, warning
	}

	body, err := ioutil.ReadAll(req.Body)
	if err != nil {
		return revision, envvars, dockerStrategyOptions, false, errors.NewBadRequest(err.Error())
	}

	if len(body) == 0 {
		return revision, envvars, dockerStrategyOptions, true, nil
	}

	internalData := &buildapi.GenericWebHookEvent{}
	versionedData := &buildv1.GenericWebHookEvent{}
	if contentType == "application/yaml" {
		body, err = yaml.ToJSON(body)
		if err != nil {
			warning := webhook.NewWarning(fmt.Sprintf("error converting payload to json: %v, ignoring payload and continuing with build", err))
			return revision, envvars, dockerStrategyOptions, true, warning
		}
	}
	if err = json.Unmarshal(body, &versionedData); err != nil {
		warning := webhook.NewWarning(fmt.Sprintf("error unmarshalling payload: %v, ignoring payload and continuing with build", err))
		return revision, envvars, dockerStrategyOptions, true, warning
	}
	if err := legacyscheme.Scheme.Convert(versionedData, internalData, nil); err != nil {
		return revision, envvars, dockerStrategyOptions, false, errors.NewBadRequest(err.Error())
	}

	if len(versionedData.Env) > 0 && trigger.AllowEnv {
		envvars = versionedData.Env
	}
	if internalData.DockerStrategyOptions != nil {
		dockerStrategyOptions = versionedData.DockerStrategyOptions
	}
	if buildCfg.Spec.Source.Git == nil {
		// everything below here is specific to git-based builds
		return revision, envvars, dockerStrategyOptions, true, nil
	}
	if internalData.Git == nil {
		warning := webhook.NewWarning("no git information found in payload, ignoring and continuing with build")
		return revision, envvars, dockerStrategyOptions, true, warning
	}

	if internalData.Git.Refs != nil {
		for _, ref := range versionedData.Git.Refs {
			if webhook.GitRefMatches(ref.Ref, webhook.DefaultConfigRef, &buildCfg.Spec.Source) {
				revision = &buildv1.SourceRevision{
					Git: &ref.GitSourceRevision,
				}
				return revision, envvars, dockerStrategyOptions, true, nil
			}
		}
		warning := webhook.NewWarning(fmt.Sprintf("skipping build. None of the supplied refs matched %q", buildCfg.Spec.Source.Git.Ref))
		return revision, envvars, dockerStrategyOptions, false, warning
	}
	if !webhook.GitRefMatches(internalData.Git.Ref, webhook.DefaultConfigRef, &buildCfg.Spec.Source) {
		warning := webhook.NewWarning(fmt.Sprintf("skipping build. Branch reference from %q does not match configuration", internalData.Git.Ref))
		return revision, envvars, dockerStrategyOptions, false, warning
	}
	revision = &buildv1.SourceRevision{
		Git: &versionedData.Git.GitSourceRevision,
	}
	return revision, envvars, dockerStrategyOptions, true, nil
}