-
Notifications
You must be signed in to change notification settings - Fork 8.7k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Suggested improvements for dataurl
#1043
Comments
IIRC macOS didn't have |
Why stop at # Create a data URL from a file
dataurl() {
# https://github.com/mathiasbynens/dotfiles/commit/5d76fc286f
# POSIX does not define `-b`/`--brief` or `--mime-type`
mimeType="$(LC_ALL='C' file -b --mime-type -- "${1-}")"
if printf -- '%s\n' "${mimeType-}" | grep -q -e '^text/'; then
mimeType="${mimeType-}"';charset=utf-8'
fi
# `uuencode` – part of POSIX since the 1900s – instead of `openssl` or `base64`
uuencode -m -- "${1-}" /dev/stdout |
# remove the first line, then the last line, then remove all newlines
sed -e '1d' -e '$d' - |
sed -e ':a' -e 'N' -e '$! b a' -e 's/\n//g' - |
awk -v mimeType="${mimeType-}" -- '{printf "data:%s;base64,%s\n", mimeType, $0}' -
# `unset` instead of non-standard `local`, but send its errors to `/dev/null` just in case
unset -v -- mimeType 2>/dev/null
} |
Thanks for explaining. I know little about macOS history
I like how you used BTW, I tried using |
BTW, speaking of special chars, I just noticed that both @mathiasbynens Should I rename this issue to " I'm willing to open a PR for this, but I don't know which commands are more appropriate. I'll do some research |
dataurl
use openssl
?dataurl
@Rudxain What do you mean with URL-safe? |
I haven't tested the output of AFAIK, most |
This comment was marked as off-topic.
This comment was marked as off-topic.
I just read Wikipedia: |
macOS and Linux distros have
base64
preinstalled, why not use it directly?The text was updated successfully, but these errors were encountered: