Fix(cf curl): Prevent errors when handling binary API responses #3604
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of the Change
Problem:
When cf cli receives binary data from the API, such as when downloading a droplet with the command
cf curl /v3/droplets/48155813-038b-4fbd-912d-7f8856c39f9c/download > /tmp/droplet
it crashes while trying to process the binary data.
Users can provide the
parameter as a workaround.
e.g:
Solution:
The fix is to detect when the response contains binary data and by writing the raw bytes directly to stdout instead of converting to string, we avoid data corruption.
Why Is This PR Valuable?
This PR would help users trying to download the binary data and trying to redirect the output using a pipe
Applicable Issues
List any applicable GitHub Issues here
How Urgent Is The Change?
Medium