@@ -17,6 +17,7 @@ package image
1717import (
1818 "encoding/json"
1919 "fmt"
20+ "io"
2021 "log"
2122 "os"
2223 "path/filepath"
@@ -31,16 +32,24 @@ func ValidateLayout(src string, refs []string, out *log.Logger) error {
3132 return validate (newPathWalker (src ), refs , out )
3233}
3334
34- // Validate walks through the given .tar file and validates the manifest
35- // pointed to by the given refs or returns an error if the validation failed.
36- func Validate (tarFile string , refs []string , out * log.Logger ) error {
35+ // ValidateFile opens the tar file given by the filename, then calls ValidateReader
36+ func ValidateFile (tarFile string , refs []string , out * log.Logger ) error {
3737 f , err := os .Open (tarFile )
3838 if err != nil {
3939 return errors .Wrap (err , "unable to open file" )
4040 }
4141 defer f .Close ()
4242
43- return validate (newTarWalker (tarFile , f ), refs , out )
43+ return Validate (f , refs , out )
44+ }
45+
46+ // Validate walks through a tar stream and validates the manifest.
47+ // * Check that all refs point to extant blobs
48+ // * Checks that all referred blobs are valid
49+ // * Checks that mime-types are correct
50+ // returns error on validation failure
51+ func Validate (r io.ReadSeeker , refs []string , out * log.Logger ) error {
52+ return validate (newTarWalker (r ), refs , out )
4453}
4554
4655var validRefMediaTypes = []string {
@@ -101,17 +110,23 @@ func UnpackLayout(src, dest, ref string) error {
101110 return unpack (newPathWalker (src ), dest , ref )
102111}
103112
104- // Unpack walks through the given .tar file and, using the layers specified in
105- // the manifest pointed to by the given ref, unpacks all layers in the given
106- // destination directory or returns an error if the unpacking failed.
107- func Unpack (tarFile , dest , ref string ) error {
108- f , err := os .Open (tarFile )
113+ // UnpackFile opens the file pointed by tarFileName and calls Unpack on it.
114+ func UnpackFile (tarFileName , dest , ref string ) error {
115+ f , err := os .Open (tarFileName )
109116 if err != nil {
110117 return errors .Wrap (err , "unable to open file" )
111118 }
112119 defer f .Close ()
113120
114- return unpack (newTarWalker (tarFile , f ), dest , ref )
121+ return Unpack (f , dest , ref )
122+ }
123+
124+ // Unpack walks through the tar stream and, using the layers specified in
125+ // the manifest pointed to by the given ref, unpacks all layers in the given
126+ // destination directory or returns an error if the unpacking failed.
127+ // The destination will be created if it does not exist.
128+ func Unpack (r io.ReadSeeker , dest , refName string ) error {
129+ return unpack (newTarWalker (r ), dest , refName )
115130}
116131
117132func unpack (w walker , dest , refName string ) error {
@@ -143,17 +158,23 @@ func CreateRuntimeBundleLayout(src, dest, ref, root string) error {
143158 return createRuntimeBundle (newPathWalker (src ), dest , ref , root )
144159}
145160
146- // CreateRuntimeBundle walks through the given .tar file and
147- // creates an OCI runtime bundle in the given destination dest
148- // or returns an error if the unpacking failed.
149- func CreateRuntimeBundle (tarFile , dest , ref , root string ) error {
161+ // CreateRuntimeBundleFile opens the file pointed by tarFile and calls
162+ // CreateRuntimeBundle.
163+ func CreateRuntimeBundleFile (tarFile , dest , ref , root string ) error {
150164 f , err := os .Open (tarFile )
151165 if err != nil {
152166 return errors .Wrap (err , "unable to open file" )
153167 }
154168 defer f .Close ()
155169
156- return createRuntimeBundle (newTarWalker (tarFile , f ), dest , ref , root )
170+ return createRuntimeBundle (newTarWalker (f ), dest , ref , root )
171+ }
172+
173+ // CreateRuntimeBundle walks through the given tar stream and
174+ // creates an OCI runtime bundle in the given destination dest
175+ // or returns an error if the unpacking failed.
176+ func CreateRuntimeBundle (r io.ReadSeeker , dest , ref , root string ) error {
177+ return createRuntimeBundle (newTarWalker (r ), dest , ref , root )
157178}
158179
159180func createRuntimeBundle (w walker , dest , refName , rootfs string ) error {
@@ -190,8 +211,7 @@ func createRuntimeBundle(w walker, dest, refName, rootfs string) error {
190211 }
191212 }
192213
193- err = m .unpack (w , filepath .Join (dest , rootfs ))
194- if err != nil {
214+ if err = m .unpack (w , filepath .Join (dest , rootfs )); err != nil {
195215 return err
196216 }
197217
0 commit comments