12345678910111213141516171819202122232425262728293031323334353637 |
- package util
- import (
- "github.com/klauspost/compress/zstd"
- "os/exec"
- "strings"
- )
- func ExpandShellString(s string) (string, error) {
- if strings.Contains(s, "$") {
- // Start a shell to expand the environment variables
- cmd := exec.Command("sh", "-c", "echo "+s)
- out, err := cmd.Output()
- if err != nil {
- return "", err
- }
- s = strings.TrimSpace(string(out))
- }
- return s, nil
- }
- func ExpandShellStringInfallible(s string) string {
- expanded, err := ExpandShellString(s)
- if err != nil {
- return s
- }
- return expanded
- }
- func DecompressZstdBuffer(input []byte) ([]byte, error) {
- decoder, err := zstd.NewReader(nil)
- if err != nil {
- return nil, err
- }
- defer decoder.Close()
- return decoder.DecodeAll(input, nil)
- }
|