func LocalBundleDataSource(path string) (BundleDataSource, error) {
	info, err := os.Stat(path)
	if err != nil {
		if isNotExistsError(err) {
			return nil, errors.NotFoundf("%q", path)
		}

		return nil, errors.Annotatef(err, "stat failed for %q", path)
	}

	// Treat as an exploded bundle archive directory
	if info.IsDir() {
		path = filepath.Join(path, "bundle.yaml")
	}

	// Try parsing as a yaml file first
	f, err := os.Open(path)
	if err != nil {
		if isNotExistsError(err) {
			return nil, errors.NotFoundf("%q", path)
		}
		return nil, errors.Annotatef(err, "access bundle data at %q", path)
	}
	defer func() { _ = f.Close() }()

	parts, pErr := parseBundleParts(f)
	if pErr == nil {
		absPath, err := filepath.Abs(path)
		if err != nil {
			return nil, errors.Annotatef(err, "resolve absolute path to %s", path)
		}
		return &resolvedBundleDataSource{
			basePath: filepath.Dir(absPath),
			parts:    parts,
		}, nil
	}

	// As a fallback, try to parse as a bundle archive
	zo := newZipOpenerFromPath(path)
	zrc, err := zo.openZip()
	if err != nil {
		// Not a zip file; return the original parse error
		return nil, errors.NewNotValid(pErr, "cannot unmarshal bundle contents")
	}
	defer func() { _ = zrc.Close() }()

	r, err := zipOpenFile(zrc, "bundle.yaml")
	if err != nil {
		// It is a zip file but not one that contains a bundle.yaml
		return nil, errors.NotFoundf("interpret bundle contents as a bundle archive: %v", err)
	}
	defer func() { _ = r.Close() }()

	if parts, pErr = parseBundleParts(r); pErr == nil {
		return &resolvedBundleDataSource{
			basePath: "", // use empty base path for archives
			parts:    parts,
		}, nil
	}

	return nil, errors.NewNotValid(pErr, "cannot unmarshal bundle contents")
}
// LocalBundleDataSource reads a (potentially multi-part) bundle from path and
// returns a BundleDataSource for it. Path may point to a yaml file, a bundle
// directory or a bundle archive.
LocalBundleDataSource reads a (potentially multi-part) bundle from path and
returns a BundleDataSource for it. Path may point to a yaml file, a bundle
directory or a bundle archive.
// LocalBundleDataSource reads a ( potentially multi - part ) bundle from path and // returns a BundleDataSource for it . Path may point to a yaml file a bundle // directory or a bundle archive .
func LocalBundleDataSource(path string) (BundleDataSource, error) {
	info, err := os.Stat(path)
	if err != nil {
		if isNotExistsError(err) {
			return nil, errors.NotFoundf("%q", path)
		}
		return nil, errors.Annotatef(err, "stat failed for %q", path)
	}
	if info.IsDir() {
		path = filepath.Join(path, "bundle.yaml")
	}
	f, err := os.Open(path)
	if err != nil {
		if isNotExistsError(err) {
			return nil, errors.NotFoundf("%q", path)
		}
		return nil, errors.Annotatef(err, "access bundle data at %q", path)
	}
	defer func() { _ = f.Close() }()
	parts, pErr := parseBundleParts(f)
	if pErr == nil {
		absPath, err := filepath.Abs(path)
		if err != nil {
			return nil, errors.Annotatef(err, "resolve absolute path to %s", path)
		}
		return &resolvedBundleDataSource{
			basePath: filepath.Dir(absPath),
			parts:    parts,
		}, nil
	}
	zo := newZipOpenerFromPath(path)
	zrc, err := zo.openZip()
	if err != nil {
		return nil, errors.NewNotValid(pErr, "cannot unmarshal bundle contents")
	}
	defer func() { _ = zrc.Close() }()
	r, err := zipOpenFile(zrc, "bundle.yaml")
	if err != nil {
		return nil, errors.NotFoundf("interpret bundle contents as a bundle archive: %v", err)
	}
	defer func() { _ = r.Close() }()
	if parts, pErr = parseBundleParts(r); pErr == nil {
		return &resolvedBundleDataSource{
			basePath: "", 
			parts:    parts,
		}, nil
	}
	return nil, errors.NewNotValid(pErr, "cannot unmarshal bundle contents")
}
func LocalBundleDataSource ( path string ) ( BundleDataSource , error ) { info , err := os . Stat ( path ) if err != nil { if isNotExistsError ( err ) { return nil , errors . NotFoundf ( " " , path ) } return nil , errors . Annotatef ( err , " " , path ) } if info . IsDir ( ) { path = filepath . Join ( path , " " ) } f , err := os . Open ( path ) if err != nil { if isNotExistsError ( err ) { return nil , errors . NotFoundf ( " " , path ) } return nil , errors . Annotatef ( err , " " , path ) } defer func ( ) { _ = f . Close ( ) } ( ) parts , pErr := parseBundleParts ( f ) if pErr == nil { absPath , err := filepath . Abs ( path ) if err != nil { return nil , errors . Annotatef ( err , " " , path ) } return & resolvedBundleDataSource { basePath : filepath . Dir ( absPath ) , parts : parts , } , nil } zo := newZipOpenerFromPath ( path ) zrc , err := zo . openZip ( ) if err != nil { return nil , errors . NewNotValid ( pErr , " " ) } defer func ( ) { _ = zrc . Close ( ) } ( ) r , err := zipOpenFile ( zrc , " " ) if err != nil { return nil , errors . NotFoundf ( " " , err ) } defer func ( ) { _ = r . Close ( ) } ( ) if parts , pErr = parseBundleParts ( r ) ; pErr == nil { return & resolvedBundleDataSource { basePath : " " , parts : parts , } , nil } return nil , errors . NewNotValid ( pErr , " " ) }
LocalBundleDataSource reads a (potentially multi-part) bundle from path and
returns a BundleDataSource for it.
LocalBundleDataSource reads a ( potentially multi - part ) bundle from path and returns a BundleDataSource for it .
// Treat as an exploded bundle archive directory // Try parsing as a yaml file first // As a fallback, try to parse as a bundle archive // Not a zip file; return the original parse error // It is a zip file but not one that contains a bundle.yaml // use empty base path for archives