I'd like to write a decoder (for example a base64
decoder) that could be used in a pipeline. Thus, I'd like to be able to output the result of the decoding to stdout
and pipe it to another executable. However, I see no Stdout.write_bytes!
function in basic-cli
. There is Stdout.write!
, but my data is not a string. Is there a good way to do it using the basic-cli
platform? Is there a reason why such a function is not included?
There should be https://github.com/roc-lang/basic-cli/blob/029a32465a9aa05d4a2eff01cb57e01f2e71430f/platform/File.roc#L82
File.write_bytes! : List U8, Str => Result {} [FileWriteErr Path IOErr]
https://roc-lang.github.io/basic-cli/0.18.0/Path/#write_bytes!
Oh... stdout :thinking:
Yeah, it looks like we don't have that right now. Should be easy to add though.
Is there a reason why such a function is not included?
Probably no one has had a use case for it before
I could see us adding these effects.
Stdout.write_bytes! : List U8 => Result {} [StdoutErr IOErr]
Stderr.write_bytes! : List U8 => Result {} [StderrErr IOErr]
I assume you can't use a Str
because you don't have utf-8.. I wonder how common that is, or what the use case is. I'm wondering if we need to research the use cases a little to design the interface -- if if just adding the effect's as above is fine.
If it mirrors file writing, I think just adding it should be fine
If we don't have it, we should also have reading bytes from stdin
We've got Stdin.bytes!
so I think that's covered
https://roc-lang.github.io/basic-cli/0.18.0/Stdin/#bytes!
I've made an issue for this and labelled it Good First Issue... https://github.com/roc-lang/basic-cli/issues/311
In case anyone would like to dip their toes into platform development.
@kukimik would you be interested?
I assume you can't use a
Str
because you don't have utf-8.. I wonder how common that is, or what the use case is.
As I tried to explain, I'd like to write a filter and use it like that (not exactly, but it gives the idea):
cat ascii_encoded_png_file | decoder_written_in_roc | png2jpg > decoded_file.jpg
So the data that decoder_written_in_roc
outputs to stdout
is binary, not utf-8.
Any binary file converter (like the png2jpg
above) would be another example.
Is there a reason why such a function is not included?
Probably no one has had a use case for it before
Ok. I thought it may be some portability issues. I think this is not obvious on Windows (see e.g. https://users.rust-lang.org/t/writing-binary-data-to-windows-stdout/66870/5, https://stackoverflow.com/questions/16888339/what-is-the-simplest-way-to-write-to-stdout-in-binary-mode).
@kukimik would you be interested?
I'll see if time permits. If there really are some issues on Windows, I may have a hard time testing it, as I do not use Windows (and I've never written a line of Rust).
So I will not claim the task, but may look into it at some point.
Last updated: Jul 06 2025 at 12:14 UTC