MCPcopy
hub / github.com/argoproj/argo-workflows / LoadToStream

Function LoadToStream

workflow/artifacts/common/load_to_stream.go:30–43  ·  view source on GitHub ↗

Use ArtifactDriver.Load() to get a stream, which we can use for all implementations of ArtifactDriver.OpenStream() that aren't yet implemented the "right way" and/or for those that don't have a natural way of streaming

(ctx context.Context, a *wfv1.Artifact, g ArtifactDriver)

Source from the content-addressed store, hash-verified

28// Use ArtifactDriver.Load() to get a stream, which we can use for all implementations of ArtifactDriver.OpenStream()
29// that aren't yet implemented the "right way" and/or for those that don't have a natural way of streaming
30func LoadToStream(ctx context.Context, a *wfv1.Artifact, g ArtifactDriver) (io.ReadCloser, error) {
31 logger := logging.RequireLoggerFromContext(ctx)
32 logger.WithField("type", reflect.TypeOf(g)).Info(ctx, "Efficient artifact streaming is not supported")
33 filename := os.TempDir() + string(os.PathSeparator) + loadToStreamPrefix + rand.String(32)
34 if err := g.Load(ctx, a, filename); err != nil {
35 return nil, err
36 }
37 f, err := os.Open(filename)
38 if err != nil {
39 _ = os.Remove(filename)
40 return nil, err
41 }
42 return &selfDestructingFile{*f}, nil
43}

Callers 5

OpenStreamMethod · 0.92
OpenStreamMethod · 0.92
OpenStreamMethod · 0.92
OpenStreamMethod · 0.92
TestLoadToStreamFunction · 0.85

Calls 6

RequireLoggerFromContextFunction · 0.92
InfoMethod · 0.65
WithFieldMethod · 0.65
LoadMethod · 0.65
RemoveMethod · 0.65
StringMethod · 0.45

Tested by 1

TestLoadToStreamFunction · 0.68