WriteArchive is a helper function to write a in-memory archive with the given mimetype to disk. Only zip and tar archives are currently supported.
(bs []byte, mimetype string, path string)
| 268 | // with the given mimetype to disk. Only zip and tar archives |
| 269 | // are currently supported. |
| 270 | func WriteArchive(bs []byte, mimetype string, path string) error { |
| 271 | // Check if we need to convert the file first! |
| 272 | var rdr io.Reader |
| 273 | switch mimetype { |
| 274 | case "application/x-tar": |
| 275 | rdr = bytes.NewReader(bs) |
| 276 | case "application/zip": |
| 277 | if zr, err := zip.NewReader(bytes.NewReader(bs), int64(len(bs))); err != nil { |
| 278 | return xerrors.Errorf("read zip file: %w", err) |
| 279 | } else if tarBytes, err := archive.CreateTarFromZip(zr, maxFileSizeBytes); err != nil { |
| 280 | return xerrors.Errorf("convert zip to tar: %w", err) |
| 281 | } else { //nolint:revive |
| 282 | rdr = bytes.NewReader(tarBytes) |
| 283 | } |
| 284 | default: |
| 285 | return xerrors.Errorf("unsupported mimetype: %s", mimetype) |
| 286 | } |
| 287 | |
| 288 | // Untar the file into the temporary directory |
| 289 | if err := provisionersdk.Untar(path, rdr); err != nil { |
| 290 | return xerrors.Errorf("untar: %w", err) |
| 291 | } |
| 292 | |
| 293 | return nil |
| 294 | } |
| 295 | |
| 296 | // VariableDefaults returns the default values for all variables in the module. |
| 297 | func (p *Parser) VariableDefaults(ctx context.Context) (map[string]string, error) { |