feat: add 'ipfs multibase' commands#8180
Conversation
There was a problem hiding this comment.
Thank you @coryschwartz, looks good, some cosmetic asks in comments inline.
Before we merge this PR, it needs tests similar to test/sharness/t0290-cid.sh.
Tests should cover:
- encoding and decoding round (
echo foo | ipfs multibase encode -b base32 | ipfs multibase decodeand expect "foo" back)- for a file
- for stdin and stdout
- error behaviors when decoder finds
- unknown base prefix
- character outside expected base dictionary
|
Cleaned up and added tests. @ribasushi @Stebalien @aschmahmann lmk if we can improve CLI ergonomics/docs here in any way for Usage examples for quick eyeballing: ipfs multibaseipfs multibase decodeipfs multibase encodeipfs multibase listThis is alias/same command as pre-existing |
|
|
@lidel another thing we may want to add here is a |
gammazero
left a comment
There was a problem hiding this comment.
Please consider my comment. I think the correct way to do this is to have a stream decoder, instead of reading the entirety of the (possibly huge) file into memory.
| if err != nil { | ||
| return fmt.Errorf("failed to access file: %w", err) | ||
| } | ||
| encoded_data, err := ioutil.ReadAll(file) |
There was a problem hiding this comment.
Would it be worth implementing a multibase Decoder that would take an io.Reader and return one as well, with a signature like NewDecoder(io.Reader) io.Reader
Then this could all be done without having to read the entire file into memory.
decReader := mbase.NewDecoder(file)
return resp.emit(decReader)@lidel Seems like this is something that should exist, or am I missing an obvious reason it does not? Seems like a NewDecode function could start reading the stream, and then construct the correct decoder and return it as an io.Reader.
There was a problem hiding this comment.
Good question! I filled upstream issue multiformats/go-multibase#44 to discuss this, but out of scope for this PR.
|
Are any of the requested changes here blocking or just improvements? If they're just improvements, can we merge and iterate? |
|
Not blocking. Only asking implementor to take note before merging. |
|
For the sake of shipping basic
@aschmahmann this PR is ready for your final 👀 and a squash-merge. |
| "decode": mbaseDecodeCmd, | ||
| "list": basesCmd, | ||
| }, | ||
| Extra: CreateCmdExtras(SetDoesNotUseRepo(true)), |
There was a problem hiding this comment.
Going to merge for now as this seems like it wouldn't hurt and matches what ipfs cid does.
However, I don't think this really works properly without applying the flag to each subcommand.
@lidel let's revisit during the RC process what we want to do here and figure out if ipfs cid has similar problems.
This is intended to implement part 1 of #7939 (comment)
Usage examples
See #8180 (comment)