Created
August 8, 2018 15:10
-
-
Save ethanpost/c2a622c9aad1017e9eab766b278a2b3f to your computer and use it in GitHub Desktop.
My implementation of a 'file_is_binary' function.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Some lines may be dependent on my framework and need to be removed or modified. Easy enough to do. | |
function file_is_binary { | |
# Return true if file is binary, false if not. | |
# >>> file_is_binary "file" | |
${arcRequireBoundVariables} | |
typeset file | |
file="${1:-}" | |
file_raise_file_not_found "${file}" && ${returnTrue} | |
[[ ! -s "${file}" ]] && ${returnFalse} | |
if boot_does_program_exist "perl"; then | |
if perl -E 'exit((-B $ARGV[0])?0:1);' "${file}"; then | |
${returnTrue} | |
else | |
${returnFalse} | |
fi | |
else | |
if (( $(diff "${file}" /etc/passwd | grep "Binary files" | wc -l) )); then | |
${returnTrue} | |
else | |
${returnFalse} | |
fi | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment