Skip to content

Instantly share code, notes, and snippets.

@ethanpost
Created August 8, 2018 15:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ethanpost/c2a622c9aad1017e9eab766b278a2b3f to your computer and use it in GitHub Desktop.
Save ethanpost/c2a622c9aad1017e9eab766b278a2b3f to your computer and use it in GitHub Desktop.
My implementation of a 'file_is_binary' function.
# 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