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

N5Factory - urls with query and/or fragment #12

Open
bogovicj opened this issue Mar 14, 2024 · 2 comments
Open

N5Factory - urls with query and/or fragment #12

bogovicj opened this issue Mar 14, 2024 · 2 comments

Comments

@bogovicj
Copy link
Collaborator

Currently, N5Factory.openReader and likely openWriter will fail if URI's with query and/or fragments are passed.

N5Reader n5 = new N5Factory().openReader("my-container.n5?img#fragment");

fails with

Exception in thread "main" org.janelia.saalfeldlab.n5.N5Exception$N5IOException: No container exists at my-container.n5?img#fragment
	at org.janelia.saalfeldlab.n5.N5KeyValueReader.<init>(N5KeyValueReader.java:144)

This just means code that calls it is responsible for providing only the container part. Alternatively, N5Factory could handle that itself, for example by using N5URI.getContainerPath

@cmhulbert
Copy link
Collaborator

cmhulbert commented Mar 18, 2024

I vote for N5Factory handling it. It's unambiguous, and while we don't use it right now, potentially we could offer some N5Factory methods in the future that may benefit from that information. It should be straight forward to do.

  1. 1. strip the leading storage format scheme
  2. 2. get the schemeSpecificPart of the remaining URI
  3. 3. substring after the first ? if present (because the query is part of the schemeSpecificPart)

N5URI has some logic to handle this already. In fact, passing the resulting URI from 1. to N5URI and calling getContainerPath() should result in the desired output, the full URI up to the query.

@bogovicj
Copy link
Collaborator Author

bogovicj commented Mar 18, 2024

Yup, what you describe does what I'd want and expect:

final String uri = ...

// remove format prefix if present
final Pair<StorageFormat, URI> formatUri = N5Factory.StorageFormat.parseUri(uri);

// make the n5uri and get the container path
new N5URI(formatUri.getB()).getContainerPath();

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

2 participants