Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for data URI scheme? #89

Closed
joouha opened this issue Mar 24, 2023 · 7 comments
Closed

Support for data URI scheme? #89

joouha opened this issue Mar 24, 2023 · 7 comments

Comments

@joouha
Copy link
Contributor

joouha commented Mar 24, 2023

Would you be interested in supporting data URIs in universal_pathlib?

A data URI consists of a scheme and a path, with no authority part, query string, or fragment. The optional media type, the optional base64 indicator, and the data are all parts of the URI path.

Most methods would be unimplemented, as the "path" is not a real hierarchical path 😃

I think the only useful method would be open, which would return the data encoded in the path.
So a DataPath wouldn't require fsspec.

@normanrz
Copy link
Collaborator

What would be the use case for this? Why not just use a bytes buffer?

@joouha
Copy link
Contributor Author

joouha commented Mar 25, 2023

My use case is for loading resources from web pages, such as images or CSS style-sheets. A resource link is typically a web address or a data URI:

<img src="http://example.com/image.png">
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==">

A DataPath class would allow universal_pathlib to be used to load both of these resources without having to handle data URIs separately - making it even more universal.

I currently have a DataPath implementation, which I register in upath.core.registry to make this work.

I was wondering if you'd consider including non-fsspec backed Path classes as part of this library?

@ap--
Copy link
Collaborator

ap-- commented Mar 25, 2023

I currently don't see how this is a good use case for upath. If I understand correctly, the only useful method would be .read_bytes(), and none of the others would make sense in this example.

Is there another example with data uris that requires more functionality for path handling?

@normanrz
Copy link
Collaborator

I agree with @ap--. If you have a DataPath implementation and can register that with upath in your application, that is great! I don't think it is a great fit for this library because there is limited added-value in terms of path handling.

@joouha
Copy link
Contributor Author

joouha commented Mar 27, 2023

Fair enough

@joouha joouha closed this as completed Mar 27, 2023
@ap--
Copy link
Collaborator

ap-- commented Nov 8, 2023

@joouha this might soon be supported ootb with release of the next fsspec version. see: fsspec/filesystem_spec#1415

We'll have to add some tests, since I believe that most of the pathlib interface will just be non-functional. But the read methods might just work!

Cheers,
Andreas 😃

@joouha
Copy link
Contributor Author

joouha commented Nov 8, 2023

Ooh! That's awesome news 😃 😃 😃

Thanks Andreas

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants