It’s currently not possible to get the safe:// url for a file without being connected to a network - see sn_api/…/subcommands/xorurl.rs#L74 which calls
Most of the logic for creating the safeurl is sn_api/…/safeurl.rs
Is it possible to use the safeurl logic elsewhere? I haven’t had any luck importing it to my test app.
safe xorurl --dry-run /tmp/data.bin should give the url without being connected to the network. But following through the chain of logic we get to safe_client.rs#L203 - “TODO: allow this operation to work without a connection when it’s a dry run”, ie dryrun is currently ignored.
I appreciate the format of safeurls is specific to sn_api (especially nrs urls); safeurls are not required to fetch data, just convenient. However I wonder if it’s worth pulling this safeurl logic out to a library since I imagine it will be the standard way to publicize and access data on the network so it perhaps should be more easily available than within sn_api?
To give my specific use case that led to this, I’m making a gui for self_encryption, and I want to show the safeurl for each chunk so they can be fetched individually from a network. But right now it’s almost impossible to easily generate safeurls. I have the content and the xorname, but it’s not easy to convert into a safeurl.
Would it be helpful to refactor into a safeurl library? sn_url? I’m happy to do this if it’s of value.
I really appreciated the example in self_encryption that builds a standalone self_encryption binary for encrypting/decrypting any file. Maybe we could also have a sn_url example binary that easily allows us to get the safeurl for any file (like what
safe xorurl --dry-run /tmp/data.bin is meant to do)?
Any thoughts on the best way to generate safeurls, without cherrypicking a bunch of code from safeurl.rs?