MCPcopy
hub / github.com/google/go-containerregistry / Export

Function Export

pkg/crane/export.go:27–55  ·  view source on GitHub ↗

Export writes the filesystem contents (as a tarball) of img to w. If img has a single layer, just write the (uncompressed) contents to w so that this "just works" for images that just wrap a single blob.

(img v1.Image, w io.Writer)

Source from the content-addressed store, hash-verified

25// If img has a single layer, just write the (uncompressed) contents to w so
26// that this "just works" for images that just wrap a single blob.
27func Export(img v1.Image, w io.Writer) error {
28 layers, err := img.Layers()
29 if err != nil {
30 return err
31 }
32 if len(layers) == 1 {
33 // If it's a single layer...
34 l := layers[0]
35 mt, err := l.MediaType()
36 if err != nil {
37 return err
38 }
39
40 if !mt.IsLayer() {
41 // ...and isn't an OCI mediaType, we don't have to flatten it.
42 // This lets export work for single layer, non-tarball images.
43 rc, err := l.Uncompressed()
44 if err != nil {
45 return err
46 }
47 defer rc.Close()
48 _, err = io.Copy(w, rc)
49 return err
50 }
51 }
52 fs := mutate.Extract(img)
53 _, err = io.Copy(w, fs)
54 return err
55}

Callers 4

TestCraneFilesystemFunction · 0.92
NewCmdExportFunction · 0.92
TestExportFunction · 0.85

Calls 6

ExtractFunction · 0.92
IsLayerMethod · 0.80
LayersMethod · 0.65
MediaTypeMethod · 0.65
UncompressedMethod · 0.65
CloseMethod · 0.65

Tested by 3

TestCraneFilesystemFunction · 0.74
TestExportFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…