Skip to content

feat: add a wrapper to blob to wrap any ReadOnlyBlob to io.ReadCloser#593

Merged
jakobmoellerdev merged 5 commits into
open-component-model:mainfrom
Skarlso:add-read-closer-wrapper
Aug 21, 2025
Merged

feat: add a wrapper to blob to wrap any ReadOnlyBlob to io.ReadCloser#593
jakobmoellerdev merged 5 commits into
open-component-model:mainfrom
Skarlso:add-read-closer-wrapper

Conversation

@Skarlso

@Skarlso Skarlso commented Aug 19, 2025

Copy link
Copy Markdown
Contributor

What this PR does / why we need it

This creates a wrapper for ReadOnlyBlobs so they can act like a MediaType aware blob.

This is part of #573.

The reason here is, that we don't want filesystem to be modified to be media type aware. Rather we can wrap it in a direct blob that will be able to call the underlying reader and even add capabilities to it, like being media type aware.

Such a wrapper could be created like this:

w := direct.New(direct.NewReadCloserWrapper(b), direct.WithMediaType(location.MediaType))

This will create a wrapper that is a blob.ReadOnlyBlob.

Which issue(s) this PR fixes

@github-actions github-actions Bot added kind/feature new feature, enhancement, improvement, extension size/m Medium labels Aug 19, 2025
On-behalf-of: gergely.brautigam@sap.com

Signed-off-by: Gergely Brautigam <182850+Skarlso@users.noreply.github.com>
@Skarlso Skarlso force-pushed the add-read-closer-wrapper branch from 6d61221 to 2fb50b3 Compare August 19, 2025 15:44
@Skarlso

Skarlso commented Aug 21, 2025

Copy link
Copy Markdown
Contributor Author

Okay, tested this wrapper in #573 ( by copying this entire implementation there ).

GOROOT=/Users/skarlso/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.25.0.darwin-arm64 #gosetup
GOPATH=/Users/skarlso/go #gosetup
/Users/skarlso/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.25.0.darwin-arm64/bin/go test -c -o /Users/skarlso/Library/Caches/JetBrains/GoLand2025.2/tmp/GoLand/___go_test_ocm_software_open_component_model_bindings_go_plugin_manager_registries_blobs.test ocm.software/open-component-model/bindings/go/plugin/manager/registries/blobs #gosetup
/Users/skarlso/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.25.0.darwin-arm64/bin/go tool test2json -t /Users/skarlso/Library/Caches/JetBrains/GoLand2025.2/tmp/GoLand/___go_test_ocm_software_open_component_model_bindings_go_plugin_manager_registries_blobs.test -test.v=test2json -test.paniconexit0 #gosetup
=== RUN   TestCreateBlobDataLocalFileSuccess
--- PASS: TestCreateBlobDataLocalFileSuccess (0.00s)
=== RUN   TestCreateBlobDataLocalFileFileNotFound
--- PASS: TestCreateBlobDataLocalFileFileNotFound (0.00s)
=== RUN   TestCreateBlobDataUnsupportedLocationType
--- PASS: TestCreateBlobDataUnsupportedLocationType (0.00s)
=== RUN   TestCreateBlobDataUnsupportedLocationTypeUnixNamedPipe
--- PASS: TestCreateBlobDataUnsupportedLocationTypeUnixNamedPipe (0.00s)
=== RUN   TestCreateBlobData_WithMediaType
--- PASS: TestCreateBlobData_WithMediaType (0.00s)
=== RUN   TestCreateBlobData_WithoutMediaType
--- PASS: TestCreateBlobData_WithoutMediaType (0.00s)
PASS

Process finished with the exit code 0

All tests passed.

By adding the wrapper to this thing:

w := direct.New(direct.NewReadCloserWrapper(b), direct.WithMediaType(location.MediaType))

And then location's Mediatype was correctly transferred.

Comment thread bindings/go/blob/direct/readcloser_wrapper.go Outdated
Comment thread bindings/go/blob/direct/readcloser_wrapper.go Outdated
On-behalf-of: gergely.brautigam@sap.com

Signed-off-by: Gergely Brautigam <182850+Skarlso@users.noreply.github.com>
@Skarlso Skarlso force-pushed the add-read-closer-wrapper branch from 3b377ca to 4322b0f Compare August 21, 2025 12:57
…t closing the reader

On-behalf-of: gergely.brautigam@sap.com

Signed-off-by: Gergely Brautigam <182850+Skarlso@users.noreply.github.com>
@Skarlso Skarlso force-pushed the add-read-closer-wrapper branch from f8ed349 to 5ab7798 Compare August 21, 2025 13:17
On-behalf-of: gergely.brautigam@sap.com

Signed-off-by: Gergely Brautigam <182850+Skarlso@users.noreply.github.com>
@jakobmoellerdev jakobmoellerdev enabled auto-merge (squash) August 21, 2025 13:54
@jakobmoellerdev jakobmoellerdev merged commit 33eace5 into open-component-model:main Aug 21, 2025
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/feature new feature, enhancement, improvement, extension size/m Medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants