// toCompressed compacts the C-node as a performance optimization.
558715
func toCompressed(cn *cNode, lev uint) *mainNode {
	tmpArray := make([]branch, len(cn.array))
	for i, sub := range cn.array {
		switch sub.(type) {
		case *iNode:
			inode := sub.(*iNode)
			mainPtr := (*unsafe.Pointer)(unsafe.Pointer(&inode.main))
			main := (*mainNode)(atomic.LoadPointer(mainPtr))
			tmpArray[i] = resurrect(inode, main)
		case *sNode:
			tmpArray[i] = sub
		default:
			panic("Ctrie is in an invalid state")
		}
	}

	return toContracted(&cNode{bmp: cn.bmp, array: tmpArray}, lev)
}
684158
func Compress(source, destination string) error {
	tarCmd := exec.Command("tar", "cf", destination, "-C", source, ".")
	if out, err := tarCmd.Output(); err != nil {
		return errors.New("running tar command: " + string(out), err)
	}
	return nil
}
612389
func (e *Encoder) UseCompactEncoding(flag bool) *Encoder {
	e.useCompact = flag
	return e
}
744520
func Compress(fileName, srcPath string, options *CompressOptions) error {
	if options == nil {
		options = &CompressOptions{}
	}

	srcInfo, err := os.Lstat(srcPath)
	if err != nil {
		return err
	}

	writer, err := newWriter(fileName, options)
	if err != nil {
		return err
	}

	// Removes the last slash to avoid different behaviors when `srcPath` is a folder
	srcPath = path.Clean(srcPath)

	// All files added are relative to the tar file
	// If IncludeSourceDir is true one level behind is added
	relPath := path.Dir(srcPath)
	if srcInfo.IsDir() && !options.IncludeSourceDir {
		relPath = srcPath
	}

	// To improve performance filters are prepared before.
	filters := prepareFilters(options.Filters)

	err = filepath.Walk(srcPath,
		func(filePath string, info os.FileInfo, err error) error {
			if err != nil {
				return err
			}

			// Makes the file to be relative to the tar file
			// We don't support absolute path while compressing
			// but it can be done further
			relFilePath, err := filepath.Rel(relPath, filePath)
			if err != nil {
				return err
			}

			// When IncludeSourceDir is false the relative path for the
			// root folder is '.', we have to ignore this folder
			if relFilePath == "." {
				return nil
			}

			// Check if we have to add the current file based on the user filters
			if !optimizedMatches(relFilePath, filters) {
				return nil
			}

			// All good, relative path made, filters applied, now we can write
			// the user file into tar file
			return writer.Write(filePath, relFilePath)
		})

	// If any error occurs we delete the tar file
	writer.Close(err != nil)

	return err
}
129758
func Compresses(exts []string) HandlerFunc {
	extsmap := make(map[string]bool)
	for _, ext := range exts {
		extsmap[strings.ToLower(ext)] = true
	}

	return func(ctx *Context) {
		ae := ctx.Req().Header.Get("Accept-Encoding")
		if ae == "" {
			ctx.Next()
			return
		}

		if len(extsmap) > 0 {
			ext := strings.ToLower(path.Ext(ctx.Req().URL.Path))
			if _, ok := extsmap[ext]; ok {
				compress(ctx, "auto")
				return
			}
		}

		if action := ctx.Action(); action != nil {
			if c, ok := action.(Compresser); ok {
				compress(ctx, c.CompressType())
				return
			}
		}

		// if blank, then no compress
		ctx.Next()
	}
}
265484
func (s SnappyCompressor) Decompress(r io.Reader) (io.Reader, error) {
	return snappy.NewReader(r), nil
}
1173944
func (m *MockRenderedJobListCompressor) Compress(arg0 templatescompiler.RenderedJobList) (templatescompiler.RenderedJobListArchive, error) {
	ret := m.ctrl.Call(m, "Compress", arg0)
	ret0, _ := ret[0].(templatescompiler.RenderedJobListArchive)
	ret1, _ := ret[1].(error)
	return ret0, ret1
}
1038689
func (e ExtFilter) ShouldCompress(r *http.Request) bool {
	ext := path.Ext(r.URL.Path)
	return e.Exts.Contains(ExtWildCard) || e.Exts.Contains(ext)
}
1235299
func (lz *Lz4) Decompress(in io.Reader, out io.Writer) error {
	r := lz4.NewReader(in)
	_, err := io.Copy(out, r)
	return err
}
312384
func (gz *Gzip) Compress(content []byte) ([]byte, error) {
	if !gz.Options.Compress {
		return content, nil
	}

	// method
	var m int
	switch gz.Options.Method {
	case "NoCompression":
		m = flate.NoCompression
		break
	case "BestSpeed":
		m = flate.BestSpeed
		break
	case "BestCompression":
		m = flate.BestCompression
		break
	default:
		m = flate.DefaultCompression
		break
	}

	// compress
	var b bytes.Buffer
	w, err := gzip.NewWriterLevel(&b, m)
	if err != nil {
		return nil, err
	}

	// insert content
	_, err = w.Write(content)
	if err != nil {
		return nil, err
	}

	err = w.Close()
	if err != nil {
		return nil, err
	}

	// compressed content
	return b.Bytes(), nil
}
1110397
func (p *Partition) compact() {
	if p.isClosing() {
		return
	} else if !p.compactionsEnabled() {
		return
	}
	interrupt := p.compactionInterrupt

	fs := p.retainFileSet()
	defer fs.Release()

	// Iterate over each level we are going to compact.
	// We skip the first level (0) because it is log files and they are compacted separately.
	// We skip the last level because the files have no higher level to compact into.
	minLevel, maxLevel := 1, len(p.levels)-2
	for level := minLevel; level <= maxLevel; level++ {
		// Skip level if it is currently compacting.
		if p.levelCompacting[level] {
			continue
		}

		// Collect contiguous files from the end of the level.
		files := fs.LastContiguousIndexFilesByLevel(level)
		if len(files) < 2 {
			continue
		} else if len(files) > MaxIndexMergeCount {
			files = files[len(files)-MaxIndexMergeCount:]
		}

		// Retain files during compaction.
		IndexFiles(files).Retain()

		// Mark the level as compacting.
		p.levelCompacting[level] = true

		// Execute in closure to save reference to the group within the loop.
		func(files []*IndexFile, level int) {
			// Start compacting in a separate goroutine.
			p.wg.Add(1)
			go func() {

				// Compact to a new level.
				p.compactToLevel(files, level+1, interrupt)

				// Ensure compaction lock for the level is released.
				p.mu.Lock()
				p.levelCompacting[level] = false
				p.mu.Unlock()
				p.wg.Done()

				// Check for new compactions
				p.Compact()
			}()
		}(files, level)
	}
}
1222051
func (c *Compressor) Compress(writer io.Writer, in []byte) error {
	if c.compressedBuf == nil {
		c.compressedBuf = make([]byte, BigBlockSize*2)
	}

	compressedBuf, err := zstd.CompressLevel(c.compressedBuf, in, 9)
	if err != nil {
		return errors.WithStack(err)
	}

	_, err = writer.Write(compressedBuf)
	if err != nil {
		return errors.WithStack(err)
	}

	return nil
}
936580
func compress(in []byte, cp Compressor, compressor encoding.Compressor) ([]byte, error) {
	if compressor == nil && cp == nil {
		return nil, nil
	}
	wrapErr := func(err error) error {
		return status.Errorf(codes.Internal, "grpc: error while compressing: %v", err.Error())
	}
	cbuf := &bytes.Buffer{}
	if compressor != nil {
		z, err := compressor.Compress(cbuf)
		if err != nil {
			return nil, wrapErr(err)
		}
		if _, err := z.Write(in); err != nil {
			return nil, wrapErr(err)
		}
		if err := z.Close(); err != nil {
			return nil, wrapErr(err)
		}
	} else {
		if err := cp.Do(cbuf, in); err != nil {
			return nil, wrapErr(err)
		}
	}
	return cbuf.Bytes(), nil
}
613391
func NewGzipCompressionLevel(level int) Compression {
	return &genericCompression{
		wf: func(w io.Writer) (io.WriteCloser, error) { return gzip.NewWriterLevel(w, level) },
		rf: func(r io.Reader) (io.ReadCloser, error) { return gzip.NewReader(r) },
	}
}
1065073
func (mr *MockRenderedJobListCompressorMockRecorder) Compress(arg0 interface{}) *gomock.Call {
	return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Compress", reflect.TypeOf((*MockRenderedJobListCompressor)(nil).Compress), arg0)
}
123908
func (fc FileCompressor) CompressFile(source, destination string) error {
	if err := fc.CheckExt(destination); err != nil {
		return err
	}
	if fc.Compressor == nil {
		return fmt.Errorf("no compressor specified")
	}
	if !fc.OverwriteExisting && fileExists(destination) {
		return fmt.Errorf("file exists: %s", destination)
	}

	in, err := os.Open(source)
	if err != nil {
		return err
	}
	defer in.Close()

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

	return fc.Compress(in, out)
}
1297099
func (p *Partition) Compact() {
	p.mu.Lock()
	defer p.mu.Unlock()
	p.compact()
}