cat myimage.png | base64 works a treat. Using bat instead errors with [bat error]: stream did not contain valid UTF-8
Binary data is currently not handled properly in bat (this is already addressed in #134, point "The standard output shall contain the sequence of bytes read from the input files. Nothing else shall be written to the standard output.").
I currently think the best way to proceed here would be to:
What do you think?
Yeah, that makes sense. Sorta matches what httpie does: https://github.com/jakubroztocil/httpie/blob/master/README.rst#binary-data
In order to start with this, I have created this small Rust library: content_inspector (docs).
After some major refactorings, I was able to implement the first part (pipe through binary data 1:1) in 226d9a573acb8025278d7afc19359ca167841536.
So this works now:
â–¶ bat test.png | base64
iVBORw0KGgoAAAANSUhEUgAAAIAAAABECAIAAADGJao+AAAAwklEQVR4Xu3UgQbDMBRA0bc03f//
b7N0VuqJEmwoc+KqNEkDh9b+2HuJu1KNO4f+AQCAAAAQAAACAEAAAAgAAAEAIAAABACAAAAQAAAC
AEAAAAgAAAEAIAAAANReamRLlPWYfNH0klxcPs+cP3NxWF+vi3lb7pa2R+vx6tHOtuN1O+a5lY3H
zgM5ya/GM5N7ZjfPq7/5yS8IgAAAEAAAAgBAAAAIAAABACAAAAQAgAAAEAAAAgBAAAAIAAABACAA
AIw322gDIPvtlmUAAAAASUVORK5CYII=
â–¶ md5sum test.png
0d7e0edf18a31b2576074e0dbd5933c4 test.png
â–¶ bat test.png | md5sum
0d7e0edf18a31b2576074e0dbd5933c4 -
The second part (detecting binary files in interactive mode) should be easy to implement with the content_inspector crate.
I'm going to close this ticket as the reported bug has been fixed. I will open a new ticket that tracks the second part.
Sounds good!
For prosperity, see #248
Most helpful comment
After some major refactorings, I was able to implement the first part (pipe through binary data 1:1) in 226d9a573acb8025278d7afc19359ca167841536.
So this works now:
The second part (detecting binary files in interactive mode) should be easy to implement with the
content_inspectorcrate.