-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
feat: add 'ipfs multibase' commands #8180
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 decode
and 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 multibase
ipfs multibase decode
ipfs multibase encode
ipfs multibase listThis is alias/same command as pre-existing
|
|
@lidel another thing we may want to add here is a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Continued in #8375 (comment)
This is intended to implement part 1 of #7939 (comment)
Usage examples
See #8180 (comment)