// ExtractTo extracts the whole archive or the given files to the
// specified destination.
// Call Flush() to apply changes before this.
358410
func (z *ZipArchive) ExtractTo(destPath string, entries ...string) (err error) {
	return z.ExtractToFunc(destPath, defaultExtractFunc, entries...)
}
488846
func extractData(txOuts []*wire.TxOut) ([]byte, error) {
	alldata := make([]byte, 0)
	empt := []byte{}

	for _, txout := range txOuts {
		pushMatrix, err := txscript.PushedData(txout.PkScript)
		if err != nil {
			return empt, err
		}

		for _, pushedD := range pushMatrix {
			alldata = append(alldata, pushedD...)
		}

	}

	return alldata, nil
}
501144
func ExtractType(opts ...interface{}) *opt.TypeOption {
	for _, o := range opts {
		if v, ok := o.(*opt.TypeOption); ok {
			return v
		}
	}
	return nil
}
473388
func (p *AssetPath) WriteTo(out io.Writer) (int64, error) {
	data, err := p.ReadFile()
	if err != nil {
		return 0, err
	}
	n, err := out.Write(data)
	return int64(n), err
}
10269
func (e *Extractor) Zip(ctx context.Context, body io.Reader, location string, rename Renamer) error {
	// read the whole body into a buffer. Not sure this is the best way to do it
	buffer := bytes.NewBuffer([]byte{})
	copyCancel(ctx, buffer, body)

	archive, err := zip.NewReader(bytes.NewReader(buffer.Bytes()), int64(buffer.Len()))
	if err != nil {
		return errors.Annotatef(err, "Read the zip file")
	}

	files := []file{}
	links := []link{}

	// We make the first pass creating the directory structure, or we could end up
	// attempting to create a file where there's no folder
	for _, header := range archive.File {
		select {
		case <-ctx.Done():
			return errors.New("interrupted")
		default:
		}

		path := header.Name

		// Replace backslash with forward slash. There are archives in the wild made with
		// buggy compressors that use backslash as path separator. The ZIP format explicitly
		// denies the use of "\" so we just replace it with slash "/".
		// Moreover it seems that folders are stored as "files" but with a final "\" in the
		// filename... oh, well...
		forceDir := strings.HasSuffix(path, "\\")
		path = strings.Replace(path, "\\", "/", -1)

		if rename != nil {
			path = rename(path)
		}

		if path == "" {
			continue
		}

		path = filepath.Join(location, path)
		info := header.FileInfo()

		switch {
		case info.IsDir() || forceDir:
			if err := e.FS.MkdirAll(path, info.Mode()|os.ModeDir|100); err != nil {
				return errors.Annotatef(err, "Create directory %s", path)
			}
		// We only check for symlinks because hard links aren't possible
		case info.Mode()&os.ModeSymlink != 0:
			f, err := header.Open()
			if err != nil {
				return errors.Annotatef(err, "Open link %s", path)
			}
			name, err := ioutil.ReadAll(f)
			if err != nil {
				return errors.Annotatef(err, "Read address of link %s", path)
			}
			links = append(links, link{Path: path, Name: string(name)})
		default:
			f, err := header.Open()
			if err != nil {
				return errors.Annotatef(err, "Open file %s", path)
			}
			var data bytes.Buffer
			if _, err := copyCancel(ctx, &data, f); err != nil {
				return errors.Annotatef(err, "Read contents of file %s", path)
			}
			files = append(files, file{Path: path, Mode: info.Mode(), Data: data})
		}
	}

	// Now we make another pass creating the files and links
	for i := range files {
		if err := e.copy(ctx, files[i].Path, files[i].Mode, &files[i].Data); err != nil {
			return errors.Annotatef(err, "Create file %s", files[i].Path)
		}
	}

	for i := range links {
		select {
		case <-ctx.Done():
			return errors.New("interrupted")
		default:
		}
		if err := e.FS.Symlink(links[i].Name, links[i].Path); err != nil {
			return errors.Annotatef(err, "Create link %s", links[i].Path)
		}
	}

	return nil
}
253415
func (z *ZipArchive) ExtractToFunc(destPath string, fn cae.HookFunc, entries ...string) (err error) {
	destPath = strings.Replace(destPath, "\\", "/", -1)
	isHasEntry := len(entries) > 0
	if Verbose {
		fmt.Println("Unzipping " + z.FileName + "...")
	}
	os.MkdirAll(destPath, os.ModePerm)
	for _, f := range z.File {
		f.Name = strings.Replace(f.Name, "\\", "/", -1)

		// Directory.
		if strings.HasSuffix(f.Name, "/") {
			if isHasEntry {
				if cae.IsEntry(f.Name, entries) {
					if err = fn(f.Name, f.FileInfo()); err != nil {
						continue
					}
					os.MkdirAll(path.Join(destPath, f.Name), os.ModePerm)
				}
				continue
			}
			if err = fn(f.Name, f.FileInfo()); err != nil {
				continue
			}
			os.MkdirAll(path.Join(destPath, f.Name), os.ModePerm)
			continue
		}

		// File.
		if isHasEntry {
			if cae.IsEntry(f.Name, entries) {
				if err = fn(f.Name, f.FileInfo()); err != nil {
					continue
				}
				err = extractFile(f, destPath)
			}
		} else {
			if err = fn(f.Name, f.FileInfo()); err != nil {
				continue
			}
			err = extractFile(f, destPath)
		}
		if err != nil {
			return err
		}
	}
	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)
}
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)
}
890079
func (b *Blacklist) GetTO(users ...*User) *BlacklistTO {
	var fromInfo, toInfo *InfoTO
	if from, e := NewUser(b.From); e == nil {
		fromInfo = from.Info().GetTO()
	}
	if to, e := NewUser(b.To); e == nil {
		toInfo = to.Info().GetTO()
	}
	return &BlacklistTO{
		original:   b,
		FromInfo:   fromInfo,
		ToInfo:     toInfo,
		Motivation: b.Motivation,
		Time:       b.Time,
		Timestamp:  b.Time.Unix(),
		Counter:    b.Counter,
	}
}
824272
func ExtractToFunc(srcPath, destPath string, fn cae.HookFunc, entries ...string) (err error) {
	z, err := Open(srcPath)
	if err != nil {
		return err
	}
	defer z.Close()
	return z.ExtractToFunc(destPath, fn, entries...)
}
36908
func (filebox *Filebox) MountTo(mountTo string, mux *http.ServeMux) {
	filebox.prefix = "/" + strings.Trim(mountTo, "/")
	mux.Handle(filebox.prefix+"/", filebox)
}
984690
func (z *Zip) Extract(source, target, destination string) error {
	// target refers to a path inside the archive, which should be clean also
	target = path.Clean(target)

	// if the target ends up being a directory, then
	// we will continue walking and extracting files
	// until we are no longer within that directory
	var targetDirPath string

	return z.Walk(source, func(f File) error {
		zfh, ok := f.Header.(zip.FileHeader)
		if !ok {
			return fmt.Errorf("expected header to be zip.FileHeader but was %T", f.Header)
		}

		// importantly, cleaning the path strips tailing slash,
		// which must be appended to folders within the archive
		name := path.Clean(zfh.Name)
		if f.IsDir() && target == name {
			targetDirPath = path.Dir(name)
		}

		if within(target, zfh.Name) {
			// either this is the exact file we want, or is
			// in the directory we want to extract

			// build the filename we will extract to
			end, err := filepath.Rel(targetDirPath, zfh.Name)
			if err != nil {
				return fmt.Errorf("relativizing paths: %v", err)
			}
			joined := filepath.Join(destination, end)

			err = z.extractFile(f, joined)
			if err != nil {
				return fmt.Errorf("extracting file %s: %v", zfh.Name, err)
			}

			// if our target was not a directory, stop walk
			if targetDirPath == "" {
				return ErrStopWalk
			}
		} else if targetDirPath != "" {
			// finished walking the entire directory
			return ErrStopWalk
		}

		return nil
	})
}
1227905
func Extract(archivePath string, extractPath string) error {
	zipPath := strings.TrimSpace(archivePath)
	destinationPath := strings.TrimSpace(extractPath)
	if zipPath == "" || destinationPath == "" {
		return fmt.Errorf("path or destination is empty")
	}
	if !files.Exists(zipPath) {
		return fmt.Errorf("%s not found", zipPath)
	}
	if !files.IsDir(dirname(destinationPath)) {
		return fmt.Errorf("%s invalid path", destinationPath)
	}
	r, err := zip.OpenReader(zipPath)
	defer r.Close()
	if err != nil {
		return err
	}
	destinationBaseDir := filepath.ToSlash(destinationPath)
	fi, err := os.Stat(destinationBaseDir)
	if err != nil {
		return err
	}
	if files.Exists(destinationPath) && !fi.IsDir() {
		return fmt.Errorf("%s exists but it is NOT a directory", destinationPath)
	}
	for _, f := range r.File {
		destination := fmt.Sprintf("%s/%s", destinationBaseDir, f.Name)
		basepath := dirname(destination)
		if err := os.MkdirAll(basepath, 0755); err != nil {
			return err
		}
		s, err := f.Open()
		defer s.Close()
		if err != nil {
			return err
		}
		dst := fmt.Sprintf("%s/%s", destinationBaseDir, f.Name)
		if files.Exists(dst) {
			continue
		}
		d, err := os.Create(dst)
		defer d.Close()
		if err != nil {
			return err
		}
		if _, err := io.Copy(d, s); err != nil {
			return err
		}
	}
	return nil
}
40096
func extractExtra(err error) Extra {
	extra := Extra{}

	currentErr := err
	for currentErr != nil {
		if errWithExtra, ok := currentErr.(errWithJustExtra); ok {
			for k, v := range errWithExtra.ExtraInfo() {
				extra[k] = v
			}
		}

		if errWithCause, ok := currentErr.(causer); ok {
			currentErr = errWithCause.Cause()
		} else {
			currentErr = nil
		}
	}

	return extra
}
760890
func (ds *DestSme) SerializeTo(w io.Writer) error {
	_, err := w.Write(ds.Bytes())
	return err
}
451029
func (p *Post) GetTO(users ...*User) *PostTO {
	return &PostTO{
		original:  p,
		Hpid:      p.Hpid,
		Pid:       p.Pid,
		Message:   p.Message,
		Time:      p.Time,
		Timestamp: p.Time.Unix(),
		Lang:      p.Lang,
		News:      p.News,
		Closed:    p.Closed,
	}
}
1032300
func extractFile(f *tar.Header, tr *tar.Reader, destPath string) error {
	filePath := path.Join(destPath, f.Name)
	os.MkdirAll(path.Dir(filePath), os.ModePerm)

	fw, err := os.Create(filePath)
	if err != nil {
		return err
	}
	defer fw.Close()

	if _, err = io.Copy(fw, tr); err != nil {
		return err
	}

	// Skip symbolic links.
	if f.FileInfo().Mode()&os.ModeSymlink != 0 {
		return nil
	}
	// Set back file information.
	if err = os.Chtimes(filePath, f.FileInfo().ModTime(), f.FileInfo().ModTime()); err != nil {
		return err
	}
	return os.Chmod(filePath, f.FileInfo().Mode())
}