util.go 589 B

1234567891011121314151617181920212223242526272829
  1. package util
  2. import (
  3. "github.com/klauspost/compress/zstd"
  4. "os/exec"
  5. "strings"
  6. )
  7. func ExpandShellString(s string) (string, error) {
  8. if strings.Contains(s, "$") {
  9. // Start a shell to expand the environment variables
  10. cmd := exec.Command("sh", "-c", "echo "+s)
  11. out, err := cmd.Output()
  12. if err != nil {
  13. return "", err
  14. }
  15. s = strings.TrimSpace(string(out))
  16. }
  17. return s, nil
  18. }
  19. func DecompressZstdBuffer(input []byte) ([]byte, error) {
  20. decoder, err := zstd.NewReader(nil)
  21. if err != nil {
  22. return nil, err
  23. }
  24. defer decoder.Close()
  25. return decoder.DecodeAll(input, nil)
  26. }