Skip to content

Allow cli/ tool to read data from stdin #108

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Warbo
Copy link

@Warbo Warbo commented Jul 11, 2025

The executable in cli/ is a nice little conversion tool: much lighter than depending on Kubo, and supports more bases than other CLIs I've found. I'm not sure if anybody's actually using it for anything, but I'd like to; however, it does a couple of things which make it unsuitable for scripting. These commits scratch that itch, so I thought I'd upstream them. If it's not appropriate then feel free to ignore me :-)

  • Taking data from arguments, but not stdin. This is especially problematic for encode, since binary data (which may contain NUL bytes, etc.) doesn't work well in argument lists; it forces shell scripts to use variables, which can't store it correctly; etc. In contrast, stdio is binary-safe, and requires no variables.
  • Outputting more than just the raw data, e.g. including a Result: prefix. This makes it less useful for programmatic use.

With these changes, the multibase executable feels more like a member of coreutils (e.g. base64), and is much easier to plug into other tools.

PS: I'm not a Rust programmer, so might have made some mistakes. It would also be nice to stream the stdio conversion, rather than reading it all into memory; but this is a less invasive change, and fine for my current needs, at least.

Warbo added 2 commits July 11, 2025 20:27
Avoid extra newlines, or additions like "Result: ", since they make the command
less useful.
This is especially useful for binary data, which may not survive in an argument
list (e.g. due to the presence of NUL bytes).

The 'encode' and 'decode' commands are now exact inverses of each other, so data
will roundtrip correctly, e.g.

    $ echo "hello world" | ./multibase encode | ./multibase decode

    hello world

    $ echo "hello world" | ./multibase encode | ./multibase decode | ./multibase encode

    z2yGEbwRFyhPZZckJm

    $ echo "hello world" | ./multibase encode

    z2yGEbwRFyhPZZckJm
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

Successfully merging this pull request may close these issues.

1 participant