Skip to content
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

Pipe image into bat gives stream did not contain valid UTF-8 #150

Closed
SimenB opened this issue May 23, 2018 · 6 comments
Closed

Pipe image into bat gives stream did not contain valid UTF-8 #150

SimenB opened this issue May 23, 2018 · 6 comments
Assignees
Labels
bug Something isn't working

Comments

@SimenB
Copy link

SimenB commented May 23, 2018

cat myimage.png | base64 works a treat. Using bat instead errors with [bat error]: stream did not contain valid UTF-8

@sharkdp sharkdp changed the title Pipe image into base64 gives [bat error]: stream did not contain valid UTF-8 Pipe image into bat gives stream did not contain valid UTF-8 May 24, 2018
@sharkdp sharkdp added bug Something isn't working help wanted Extra attention is needed labels May 24, 2018
@sharkdp
Copy link
Owner

sharkdp commented May 24, 2018

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:

  • Pipe through binary data 1:1 if we are writing to a pipe/file.
  • Show a user-friendly error message ("Skipping binary file" or similar) if we are writing to an interactive terminal.

What do you think?

@SimenB
Copy link
Author

SimenB commented May 24, 2018

Yeah, that makes sense. Sorta matches what httpie does: https://github.com/jakubroztocil/httpie/blob/master/README.rst#binary-data

@sharkdp sharkdp self-assigned this Jun 3, 2018
@sharkdp
Copy link
Owner

sharkdp commented Jun 3, 2018

In order to start with this, I have created this small Rust library: content_inspector (docs).

@sharkdp sharkdp mentioned this issue Jul 31, 2018
@sharkdp sharkdp added this to the v0.5.0 milestone Aug 18, 2018
@sharkdp sharkdp removed the help wanted Extra attention is needed label Aug 22, 2018
sharkdp added a commit that referenced this issue Aug 23, 2018
Use a loop-through mode that simply copies input to output if a
non-interactive terminal is detected.

see #150
@sharkdp
Copy link
Owner

sharkdp commented Aug 23, 2018

After some major refactorings, I was able to implement the first part (pipe through binary data 1:1) in 226d9a5.

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.

@sharkdp sharkdp removed this from the v0.6.0 milestone Aug 28, 2018
@sharkdp
Copy link
Owner

sharkdp commented Aug 31, 2018

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.

@SimenB
Copy link
Author

SimenB commented Sep 1, 2018

Sounds good!

For prosperity, see #248

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants