Encode and restore a file with base64 on macOS and GNU/Linux
Use native command flags for the same small PNG, then compare the original with the decoded file using cmp. No binary data needs to go to the terminal.
Put the sample in a fresh working directory
Download the original PNG below as sample-grid.png. Passing it as a file preserves every byte. Use an empty directory because the example writes sample.b64 and restored.png beside the original.
Run the pair for your operating system
The macOS system tool uses -i and -o for paths and -D for decoding. GNU coreutils supports --wrap=0 to suppress wrapped lines in encoded output. Run the two lines for your implementation, then run the shared cmp command at the end.
# macOS
base64 -i sample-grid.png -o sample.b64
base64 -D -i sample.b64 -o restored.png
# GNU/Linux (GNU coreutils)
base64 --wrap=0 sample-grid.png > sample.b64
base64 --decode sample.b64 > restored.png
# macOS / Linux
cmp sample-grid.png restored.png && echo OKRead the comparison result
If the restored bytes match, cmp succeeds and the shell prints OK. If an option is rejected, use command -v base64 to see which executable your shell chose. If the local round trip works but an API rejects the result, check whether it expects a single-line field.