MCPcopy Create free account
hub / github.com/coder/coder / WriteArchive

Function WriteArchive

provisioner/terraform/tfparse/tfparse.go:270–294  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

268// with the given mimetype to disk. Only zip and tar archives
269// are currently supported.
270func 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.
297func (p *Parser) VariableDefaults(ctx context.Context) (map[string]string, error) {

Calls 3

CreateTarFromZipFunction · 0.92
UntarFunction · 0.92
ErrorfMethod · 0.45

Tested by 3

TestTemplatePushFunction · 0.74