// GenZshCompletion generates a zsh completion file and writes to the passed writer.
356743
func (c *Command) GenZshCompletion(w io.Writer) error {
	buf := new(bytes.Buffer)

	writeHeader(buf, c)
	maxDepth := maxDepth(c)
	writeLevelMapping(buf, maxDepth)
	writeLevelCases(buf, maxDepth, c)

	_, err := buf.WriteTo(w)
	return err
}
452946
func genSearchTypes() error {
	sourceFile := filepath.Join(pkRoot, filepath.FromSlash("pkg/search/describe.go"))
	outputFile := filepath.Join(pkRoot, filepath.FromSlash("app/publisher/js/zsearch.go"))
	fi1, err := os.Stat(sourceFile)
	if err != nil {
		return err
	}
	fi2, err := os.Stat(outputFile)
	if err != nil && !os.IsNotExist(err) {
		return err
	}
	if err == nil && fi2.ModTime().After(fi1.ModTime()) {
		return nil
	}
	cmd := exec.Command("go", "generate", "-tags=js", "-v", "perkeep.org/app/publisher/js")
	if out, err := cmd.CombinedOutput(); err != nil {
		return fmt.Errorf("go generate for publisher js error: %v, %v", err, string(out))
	}
	log.Printf("generated %v", outputFile)
	return nil
}
1089930
func NewWriter(w io.Writer) *Writer {
	z, _ := NewWriterLevelDict(w, DefaultCompression, nil)
	return z
}
1362435
func (b *Bar) AppendCompleted() *Bar {
	b.AppendFunc(func(b *Bar) string {
		return b.CompletedPercentString()
	})
	return b
}
1033876
func (r *ResponseFilterWriter) WriteHeader(code int) {
	// Determine if compression should be used or not.
	r.shouldCompress = true
	for _, filter := range r.filters {
		if !filter.ShouldCompress(r) {
			r.shouldCompress = false
			break
		}
	}

	if r.shouldCompress {
		// replace discard writer with ResponseWriter
		if gzWriter, ok := r.gzipResponseWriter.Writer().(*gzip.Writer); ok {
			gzWriter.Reset(r.ResponseWriter)
		}
		// use gzip WriteHeader to include and delete
		// necessary headers
		r.gzipResponseWriter.WriteHeader(code)
	} else {
		r.ResponseWriter.WriteHeader(code)
	}
	r.statusCodeWritten = true
}
402736
func (w *tWriter) finish() (f *tFile, err error) {
	defer w.close()
	err = w.tw.Close()
	if err != nil {
		return
	}
	if !w.t.noSync {
		err = w.w.Sync()
		if err != nil {
			return
		}
	}
	f = newTableFile(w.fd, int64(w.tw.BytesLen()), internalKey(w.first), internalKey(w.last))
	return
}
356389
func GzipLevel(level int) pure.Middleware {

	// test gzip level, then don't have to each time one is created
	// in the pool

	if _, err := gzip.NewWriterLevel(ioutil.Discard, level); err != nil {
		panic(err)
	}

	var gzipPool = sync.Pool{
		New: func() interface{} {
			z, _ := gzip.NewWriterLevel(ioutil.Discard, level)

			return &gzipWriter{Writer: z}
		},
	}

	return func(next http.HandlerFunc) http.HandlerFunc {
		return func(w http.ResponseWriter, r *http.Request) {

			w.Header().Add(pure.Vary, pure.AcceptEncoding)

			if strings.Contains(r.Header.Get(pure.AcceptEncoding), pure.Gzip) {

				gz := gzipPool.Get().(*gzipWriter)
				gz.sniffComplete = false
				gzr := gz.Writer.(*gzip.Writer)
				gzr.Reset(w)
				gz.ResponseWriter = w

				w.Header().Set(pure.ContentEncoding, pure.Gzip)

				w = gz
				defer func() {

					if !gz.sniffComplete {
						// We have to reset response to it's pristine state when
						// nothing is written to body.
						w.Header().Del(pure.ContentEncoding)
						gzr.Reset(ioutil.Discard)
					}

					gzr.Close()
					gzipPool.Put(gz)
				}()
			}

			next(w, r)
		}
	}
}
830962
func _completion_function(p *C.char, _i C.int) *C.char {
	C.rl_completion_append_character = C.int(CompletionAppendChar)
	i := int(_i)
	if i == 0 {
		es := Completer(C.GoString(p), C.GoString(C.rl_line_buffer))
		entries = make([]*C.char, len(es))
		for i, x := range es {
			entries[i] = C.CString(x)
		}
	}
	if i >= len(entries) {
		return nil
	}
	return entries[i]
}
1102354
func Complete(crc uint16, table *Table) uint16 {
	if table.params.RefOut {
		return utils.ReverseUint16(crc) ^ table.params.XorOut
	}
	return crc ^ table.params.XorOut
}
177479
func NewCmdCompletion(out io.Writer, boilerPlate string) *cobra.Command {
	cmd := &cobra.Command{
		Use:     "completion SHELL",
		Short:   "Output shell completion code for the specified shell (bash or zsh)",
		Long:    completionLong,
		Example: completionExample,
		Run: func(cmd *cobra.Command, args []string) {
			err := RunCompletion(out, boilerPlate, cmd, args)
			kubeadmutil.CheckErr(err)
		},
		ValidArgs: GetSupportedShells(),
	}

	return cmd
}
1310830
func DefaultAppComplete(c *Context) {
	for _, command := range c.App.Commands {
		if command.Hidden {
			continue
		}
		if os.Getenv("_CLI_ZSH_AUTOCOMPLETE_HACK") == "1" {
			for _, name := range command.Names() {
				fmt.Fprintf(c.App.Writer, "%s:%s\n", name, command.Usage)
			}
		} else {
			for _, name := range command.Names() {
				fmt.Fprintf(c.App.Writer, "%s\n", name)
			}
		}
	}
}
107044
func (s *storageImpl) finishAndForcedHash(c context.Context, op *upload.Operation, hash *api.ObjectRef) (*upload.Operation, error) {
	gs := s.getGS(c)
	cfg, err := s.settings(c)
	if err != nil {
		return nil, err
	}

	// Try to move the object into the final location. This may fail
	// transiently, in which case we ask the client to retry, or fatally, in
	// which case we close the upload operation with an error.
	pubErr := gs.Publish(c, cfg.ObjectPath(hash), op.TempGSPath, -1)
	if transient.Tag.In(pubErr) {
		return nil, errors.Annotate(pubErr, "failed to publish the object").
			Tag(grpcutil.InternalTag).Err()
	}

	// Try to remove the leftover garbage. See maybeDelete doc for possible
	// caveats.
	if err := s.maybeDelete(c, gs, op.TempGSPath); err != nil {
		return nil, err
	}

	// Set the status of the operation based on whether we published the file
	// or not.
	return op.Advance(c, func(_ context.Context, op *upload.Operation) error {
		if pubErr != nil {
			op.Status = api.UploadStatus_ERRORED
			op.Error = fmt.Sprintf("Failed to publish the object - %s", pubErr)
		} else {
			op.Status = api.UploadStatus_PUBLISHED
			op.HashAlgo = hash.HashAlgo
			op.HexDigest = hash.HexDigest
		}
		return nil
	})
}
1049634
func GZIPCompress(src io.Reader, writeTo io.Writer) (err error) {
	w := gzip.NewWriter(writeTo)
	_, err = io.Copy(w, src)
	if err != nil {
		return
	}

	w.Flush()
	return w.Close()
}
1357887
func writeTarGz(path string, tarWriter *tar.Writer, fileInfo os.FileInfo, subPath string) error {
	file, err := os.Open(path)
	if err != nil {
		return err
	}
	defer file.Close()

	evaledPath, err := filepath.EvalSymlinks(path)
	if err != nil {
		return err
	}

	subPath, err = filepath.EvalSymlinks(subPath)
	if err != nil {
		return err
	}

	link := ""
	if evaledPath != path {
		link = evaledPath
	}

	header, err := tar.FileInfoHeader(fileInfo, link)
	if err != nil {
		return err
	}
	header.Name = evaledPath[len(subPath):]

	err = tarWriter.WriteHeader(header)
	if err != nil {
		return err
	}

	_, err = io.Copy(tarWriter, file)
	if err != nil {
		return err
	}

	return err
}
135962
func newCompletion(w io.Writer) func(*cobra.Command, []string) int {
	return func(cmd *cobra.Command, args []string) int {
		return runCompletion(w, cmd, args)
	}
}
1139234
func (s *Action) CompletionFish(c *cli.Context, a *cli.App) error {
	comp, err := fishcomp.GetCompletion(a)
	if err != nil {
		return err
	}

	fmt.Fprintln(stdout, comp)
	return nil
}
793414
func (w *gzipResponseWriter) WriteHeader(code int) {
	w.Header().Del("Content-Length")
	w.Header().Set("Content-Encoding", "gzip")
	w.Header().Add("Vary", "Accept-Encoding")
	w.ResponseWriter.WriteHeader(code)
	w.statusCodeWritten = true
}