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

fpb should detect when given binary input #76

Open
chriskuehl opened this issue Apr 17, 2019 · 2 comments
Open

fpb should detect when given binary input #76

chriskuehl opened this issue Apr 17, 2019 · 2 comments

Comments

@chriskuehl
Copy link
Owner

This isn't so great:

baisang@redacted ~> fpb logs.zip
Traceback (most recent call last):
  File "/usr/bin/fpb", line 11, in <module>
    sys.exit(paste_main())
  File "/opt/venvs/fluffy/lib/python3.6/site-packages/fluffy_cli/main.py", line 200, in paste_main
    return paste(args.server, args.file, args.language, args.regex, auth, args.direct_link, args.tee)
  File "/opt/venvs/fluffy/lib/python3.6/site-packages/fluffy_cli/main.py", line 95, in paste
    content = f.read()
  File "/opt/venvs/fluffy/lib/python3.6/codecs.py", line 321, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x91 in position 12: invalid start byte

Let's detect when given a binary file and either upload it as a file automatically, or suggest using fput instead. It definitely shouldn't crash like this.

@chriskuehl
Copy link
Owner Author

How to tell if a file is binary? Maybe using identify, like in fluffy-server?

fluffy/fluffy/models.py

Lines 128 to 132 in a3b1709

@cached_property
def probably_binary(self):
p = not identify.is_text(self.open_file)
self.open_file.seek(0)
return p

@chriskuehl
Copy link
Owner Author

chriskuehl commented Oct 21, 2021

Using identify doesn't work (unless we copy the function inline) since we don't want to add any additional dependencies to the cli. Maybe just check if it can be decoded?

I could imagine something like:

$ fpb some-file.bin
This file can't be decoded using UTF-8! This may indicate that it's a binary file, or using an unusual encoding.
What do you want to do?
  (1) Upload it as text, decoded using latin-1. This may produce garbled text.
  (2) Upload it as a binary file.

(For interactive use cases, of course.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant