func RecompressAllIn(basePath string) error {
	log.Info().Msg("Recompressing layer files...")
	pool := pond.New(runtime.NumCPU(), 1000)
	err := filepath.WalkDir(basePath, func(p string, d fs.DirEntry, err error) error {
		if err != nil {
			return err
		}
		if !strings.HasSuffix(p, Suffix) {
			return nil
		}
		compressedPath := strings.TrimSuffix(p, Suffix)
		if _, err := os.Stat(compressedPath); err == nil {
			return nil
		}
		pool.Submit(func() {
			if err := compress(p, compressedPath); err != nil {
				log.Error().Err(err)
			}
		})
		return nil
	})
	if err != nil {
		return err
	}
	pool.StopAndWait()
	if pool.FailedTasks() != 0 {
		return errors.Errorf("Error while decompressing files in %v", basePath)
	}
	return nil
}
RecompressAllIn recompresses any gzip files decompressed by Decompress
package gzip
import (
	"compress/gzip"
	"github.com/alitto/pond"
	"github.com/moio/booster/util"
	"github.com/pkg/errors"
	"github.com/rs/zerolog/log"
	"io"
	"io/fs"
	"os"
	"path/filepath"
	"runtime"
	"strings"
)
const Suffix = "_UNGZIPPED_BY_BOOSTER"
func DecompressWalking(root string) (*util.FileSet, error) {
	paths := util.NewFileSet()
	err := filepath.WalkDir(root, func(p string, d fs.DirEntry, err error) error {
		if d.Type().IsDir() && d.Name() == "booster" {
			return fs.SkipDir
		}
		if !d.Type().IsRegular() {
			return nil
		}
		if strings.HasSuffix(p, Suffix) {
			return nil
		}
		paths.Add(p)
		return nil
	})
	if err != nil {
		return nil, err
	}
	return Decompress(paths), nil
}
func Decompress(files *util.FileSet) *util.FileSet {
	log.Info().Msg("Decompressing layers...")
	processedPaths := make(chan string, runtime.NumCPU()*2)
	files.Walk(func(path string) {
		uncompressedPath := path + Suffix
		go func() {
			if decompress(path, uncompressedPath) {
				processedPaths <- uncompressedPath
			} else {
				processedPaths <- path
			}
		}()
	})
	result := util.NewFileSet()
	for i := 0; i < files.Len(); i++ {
		processedPath := <-processedPaths
		result.Add(processedPath)
		for processedPath != filepath.Dir(processedPath) {
			processedPath = filepath.Dir(processedPath)
			result.Add(processedPath)
		}
	}
	return result
}
func decompress(sourcePath string, destinationPath string) bool {
	if _, err := os.Stat(destinationPath); err == nil {
		return true
	}
	source, err := os.Open(sourcePath)
	if err != nil {
		log.Error().Str("path", sourcePath).Err(err).Msg("could not open to attempt decompression")
		return false
	}
	rreader, err := NewRecompressibilityReader(source)
	if err == gzip.ErrHeader || err == io.EOF {
		closeAndLog(source)
		return false
	}
	if err != nil {
		log.Error().Str("path", sourcePath).Err(err).Msg("error while initing decompression")
		closeAndLog(source)
		return false
	}
	destination, err := os.Create(destinationPath)
	if err != nil {
		log.Error().Str("path", destinationPath).Err(err).Msg("could not create temporary file to attempt decompression")
		closeAndLog(source)
		return false
	}
	_, err = io.Copy(destination, rreader)
	if err != nil {
		log.Error().Str("path", sourcePath).Err(err).Msg("error while decompressing")
		closeAndLog(destination)
		removeAndLog(destinationPath)
		closeAndLog(source)
		return false
	}
	err = rreader.Close()
	if err != nil {
		log.Error().Str("path", sourcePath).Err(err).Msg("error while closing recompressibility reader")
		closeAndLog(destination)
		removeAndLog(destinationPath)
		closeAndLog(source)
		return false
	}
	closeAndLog(destination)
	closeAndLog(source)
	if !rreader.TransparentlyRecompressible() {
		removeAndLog(destinationPath)
		return false
	}
	return true
}
func closeAndLog(f *os.File) {
	err := f.Close()
	if err != nil {
		log.Error().Str("path", f.Name()).Err(err).Msg("error while closing")
	}
}
func removeAndLog(path string) {
	if err := os.Remove(path); err != nil {
		log.Error().Str("path", path).Err(err).Msg("error while removing")
	}
}