CLI tool for encoding files for inline embedding in HTML pages
npm install encode-site -g
Before encoding files, you check what encoding types are available. Luckily, using the list
action will do this.
encode list
Encoding a file is pretty simple. Specify what encoding type you wish to use as the action and follow with the path to the file. This command will result in the encoding outputted to the terminal.
encode base64 index.html
Encoding a file and then saving it to a file is also rather simple. Use the output
flag (-o
or --output
) followed by the location of the new file you wish to save. This will save the encoded data to the file index.html.base64
in the current directory.
encode base64 index.html -o index.html.base64
The wrapping is the information that is inserted at the start of the encoded data, for example data:text/html;base64,
. If you simply want to encode a file without the wrapping, use the minmal
flag (-m
or --minimal
). Like all flags, it can be used with other flags.
encode base64 index.html -mo index.html.base64
encode-site
assumes a lot of information about the file for wrapping. By default, encode-site
will use the text
type and use the found extension of the specified file (an error will be given if no extension is found).
In the example, data:[type]/html;base64,
, [type]
is where the type
information is inserted. To specify a custom type (needed for images) simply the use type
flag (-t
or --type
).
encode base64 image.png -t image
In the example, data:text/[extension];base64,
, [extension]
is where the extension
information is inserted. To specify a custom extension simply the use extension
flag (-e
or --extension
).
encode base64 image -t image -e png