github.com/cloudberrydb/gpbackup@v1.0.3-0.20240118031043-5410fd45eed6/utils/compression.go (about)

     1  package utils
     2  
     3  import "fmt"
     4  
     5  var (
     6  	pipeThroughProgram PipeThroughProgram
     7  )
     8  
     9  type PipeThroughProgram struct {
    10  	Name          string
    11  	OutputCommand string
    12  	InputCommand  string
    13  	Extension     string
    14  }
    15  
    16  func InitializePipeThroughParameters(compress bool, compressionType string, compressionLevel int) {
    17  	if !compress {
    18  		pipeThroughProgram = PipeThroughProgram{Name: "cat", OutputCommand: "cat -", InputCommand: "cat -", Extension: ""}
    19  		return
    20  	}
    21  
    22  	// backward compatibility for inputs without compressionType
    23  	if compressionType == "" {
    24  		compressionType = "gzip"
    25  	}
    26  
    27  	if compressionType == "gzip" {
    28  		pipeThroughProgram = PipeThroughProgram{Name: "gzip", OutputCommand: fmt.Sprintf("gzip -c -%d", compressionLevel), InputCommand: "gzip -d -c", Extension: ".gz"}
    29  		return
    30  	}
    31  
    32  	if compressionType == "zstd" {
    33  		pipeThroughProgram = PipeThroughProgram{Name: "zstd", OutputCommand: fmt.Sprintf("zstd --compress -%d -c", compressionLevel), InputCommand: "zstd --decompress -c", Extension: ".zst"}
    34  		return
    35  	}
    36  }
    37  
    38  func GetPipeThroughProgram() PipeThroughProgram {
    39  	return pipeThroughProgram
    40  }
    41  
    42  func SetPipeThroughProgram(compression PipeThroughProgram) {
    43  	pipeThroughProgram = compression
    44  }