@@ -181,7 +181,7 @@ func (p *Package) Zip(path string) error {
181181 fPaths := []string {descriptorPath }
182182 for _ , r := range p .resources {
183183 for _ , p := range r .path {
184- c , err := read (filepath .Join (r .basePath , p ))
184+ _ , c , err := read (filepath .Join (r .basePath , p ))
185185 if err != nil {
186186 return err
187187 }
@@ -293,7 +293,7 @@ func FromString(in string, basePath string, loaders ...validator.RegistryLoader)
293293// Load the data package descriptor from the specified URL or file path.
294294// If path has the ".zip" extension, it will be saved in local filesystem and decompressed before loading.
295295func Load (path string , loaders ... validator.RegistryLoader ) (* Package , error ) {
296- contents , err := read (path )
296+ localPath , contents , err := read (path )
297297 if err != nil {
298298 return nil , fmt .Errorf ("error reading path contents (%s): %w" , path , err )
299299 }
@@ -305,34 +305,47 @@ func Load(path string, loaders ...validator.RegistryLoader) (*Package, error) {
305305 if err != nil {
306306 return nil , fmt .Errorf ("error creating temporary directory: %w" , err )
307307 }
308- fNames , err := unzip (path , dir )
308+ fNames , err := unzip (localPath , dir )
309309 if err != nil {
310- return nil , fmt .Errorf ("error unzipping path contents (%s): %w" , path , err )
310+ return nil , fmt .Errorf ("error unzipping path contents (%s): %w" , localPath , err )
311311 }
312312 if _ , ok := fNames [descriptorFileNameWithinZip ]; ok {
313313 return Load (filepath .Join (dir , descriptorFileNameWithinZip ), loaders ... )
314314 }
315- return nil , fmt .Errorf ("zip file %s does not contain a file called %s" , path , descriptorFileNameWithinZip )
315+ return nil , fmt .Errorf ("zip file %s does not contain a file called %s" , localPath , descriptorFileNameWithinZip )
316316}
317317
318- func read (path string ) ([]byte , error ) {
318+ func read (path string ) (string , []byte , error ) {
319319 if strings .HasPrefix (path , "http" ) {
320320 resp , err := http .Get (path )
321321 if err != nil {
322- return nil , fmt .Errorf ("error performing HTTP GET(%s): %w" , path , err )
322+ return "" , nil , fmt .Errorf ("error performing HTTP GET(%s): %w" , path , err )
323323 }
324324 defer resp .Body .Close ()
325325 buf , err := ioutil .ReadAll (resp .Body )
326326 if err != nil {
327- return nil , fmt .Errorf ("error reading response body contents (%s): %w" , path , err )
327+ return "" , nil , fmt .Errorf ("error reading response body contents (%s): %w" , path , err )
328328 }
329- return buf , nil
329+ // Making sure zip file is materialized.
330+ // This makes debugging easier.
331+ localPath , err := func () (string , error ) {
332+ f , err := ioutil .TempFile ("" , "*.zip" )
333+ if err != nil {
334+ return "" , fmt .Errorf ("error creating temp file to save zip (dir:%s): %w" , os .TempDir (), err )
335+ }
336+ defer f .Close ()
337+ if _ , err := f .Write (buf ); err != nil {
338+ return f .Name (), fmt .Errorf ("error writing temp file to save zip (%s): %w" , f .Name (), err )
339+ }
340+ return f .Name (), nil
341+ }()
342+ return localPath , buf , err
330343 }
331344 buf , err := ioutil .ReadFile (path )
332345 if err != nil {
333- return nil , fmt .Errorf ("error reading local file contents (%s): %w" , path , err )
346+ return "" , nil , fmt .Errorf ("error reading local file contents (%s): %w" , path , err )
334347 }
335- return buf , nil
348+ return path , buf , nil
336349}
337350
338351func unzip (archive , basePath string ) (map [string ]struct {}, error ) {
0 commit comments