-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* auto update vendor hash * separate internal and external usage * fix blobaccess doc.go * add Validate description --------- Co-authored-by: ocmbot[bot] <125909804+ocmbot[bot]@users.noreply.github.com>
- Loading branch information
1 parent
bbddd51
commit a8664a4
Showing
196 changed files
with
2,101 additions
and
1,406 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package blobaccess | ||
|
||
import ( | ||
"bytes" | ||
"io" | ||
|
||
"github.com/mandelsoft/filepath/pkg/filepath" | ||
"github.com/opencontainers/go-digest" | ||
|
||
"github.com/open-component-model/ocm/pkg/blobaccess/bpi" | ||
"github.com/open-component-model/ocm/pkg/iotools" | ||
mimetypes "github.com/open-component-model/ocm/pkg/mime" | ||
) | ||
|
||
type bytesAccess struct { | ||
_nopCloser | ||
data []byte | ||
origin string | ||
} | ||
|
||
func DataAccessForData(data []byte, origin ...string) bpi.DataSource { | ||
path := "" | ||
if len(origin) > 0 { | ||
path = filepath.Join(origin...) | ||
} | ||
return &bytesAccess{data: data, origin: path} | ||
} | ||
|
||
func DataAccessForString(data string, origin ...string) bpi.DataSource { | ||
return DataAccessForData([]byte(data), origin...) | ||
} | ||
|
||
func (a *bytesAccess) Get() ([]byte, error) { | ||
return a.data, nil | ||
} | ||
|
||
func (a *bytesAccess) Reader() (io.ReadCloser, error) { | ||
return iotools.ReadCloser(bytes.NewReader(a.data)), nil | ||
} | ||
|
||
func (a *bytesAccess) Origin() string { | ||
return a.origin | ||
} | ||
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
|
||
// ForString wraps a string into a BlobAccess, which does not need a close. | ||
func ForString(mime string, data string) bpi.BlobAccess { | ||
if mime == "" { | ||
mime = mimetypes.MIME_TEXT | ||
} | ||
return ForData(mime, []byte(data)) | ||
} | ||
|
||
func ProviderForString(mime, data string) bpi.BlobAccessProvider { | ||
return bpi.BlobAccessProviderFunction(func() (bpi.BlobAccess, error) { | ||
return ForString(mime, data), nil | ||
}) | ||
} | ||
|
||
// ForData wraps data into a BlobAccess, which does not need a close. | ||
func ForData(mime string, data []byte) bpi.BlobAccess { | ||
if mime == "" { | ||
mime = mimetypes.MIME_OCTET | ||
} | ||
return bpi.ForStaticDataAccessAndMeta(mime, DataAccessForData(data), digest.FromBytes(data), int64(len(data))) | ||
} | ||
|
||
func ProviderForData(mime string, data []byte) bpi.BlobAccessProvider { | ||
return bpi.BlobAccessProviderFunction(func() (bpi.BlobAccess, error) { | ||
return ForData(mime, data), nil | ||
}) | ||
} |
Oops, something went wrong.