create a file in a temp dir with contents of data
(ctx context.Context, data, prefix string)
| 80 | |
| 81 | // create a file in a temp dir with contents of data |
| 82 | func WriteTempFile(ctx context.Context, data, prefix string) (string, error) { |
| 83 | fs := FS(ctx) |
| 84 | file, err := afero.TempFile(fs, "", fmt.Sprintf("%s*", prefix)) |
| 85 | if err != nil { |
| 86 | return "", err |
| 87 | } |
| 88 | path := file.Name() |
| 89 | if _, err := file.WriteString(data); err != nil { |
| 90 | _ = fs.Remove(path) |
| 91 | return "", err |
| 92 | } |
| 93 | return path, nil |
| 94 | } |
| 95 | |
| 96 | // detect if the EC_EXPERIMENTAL env var is set to enable experimental features |
| 97 | func Experimental() bool { |