How can I easily obtain the DataURI of a file in a terminal-based environment? The tool should be installable via apt-get and feature simple syntax. Could you suggest some suitable options? Thank you for your assistance.
2 Answers
Since data URIs are just a combo of mime type + base64 encoded contents, you can easily create your own script to create a full string. Example from here:
#!/bin/sh
mimetype=$(file -bN --mime-type "$1")
content=$(base64 -w0 < "$1")
echo "url('data:$mimetype;base64,$content')"
I figured out that there was a built in tool for that. Typing base64 file.txt > txtbase64.txt
will save the DataURI for file.txt
inside txtbase64.txt
.