[rfc] Implement an ObjectUrl wrapper #231
Merged
+105
−6
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Rationale
The
createObjectUrl
API is offered by the browser to create URLs from Blobs that are too large to represent as data urls. The resulting url is along the lines ofblob:[origin]://[uuid]
. There's a counter partrevokeObjectURL
that releases the URL again. Rust lends itself to an abstraction that automatically revokes the url when it is not need any longer.The API
A
struct ObjectUrl
abstracts the allocation of a specific ObjectUrl. It uses reference counting to revoke the Url after the last user drops its use. It can be created from aBlob
,File
or directly from aweb_sys::Blob
. ADeref
implemention allows access to the stringly-typed url under-the-hood.