diff options
Diffstat (limited to 'macros/latex/contrib/media4svg/media4svg.lua')
-rwxr-xr-x | macros/latex/contrib/media4svg/media4svg.lua | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/macros/latex/contrib/media4svg/media4svg.lua b/macros/latex/contrib/media4svg/media4svg.lua index ae291a368e..6abc26d339 100755 --- a/macros/latex/contrib/media4svg/media4svg.lua +++ b/macros/latex/contrib/media4svg/media4svg.lua @@ -1,9 +1,9 @@ #!/usr/bin/env texlua -------------------------------------------------------------------------------- +-- ============================================================================ -- -- media4svg.lua -- --- base64 encoding utility, version 2020/04/09 +-- base64 encoding utility, version 2022/08/12 -- -- (C) 2020-today, Alexander Grahn, using code by Alex Kloss -- @@ -11,22 +11,26 @@ -- -- 1. as a commandline utility: -- --- texlua media4svg.lua <file> +-- texlua media4svg.lua <file> [<chunksize>] -- -- 2. as a library from within LuaTeX input: -- -- \directlua{require('media4svg')} -- \directlua{media4svg.base64("<file>",<chunksize>,"<end-of-line string>")} -- --- <file> string; file name --- <chunksize> integer, multiple of 3; size of binary data (bytes) --- to be converted at a time --- <end-of-line string> a string to be appended at the end of every output --- line +-- The output is placed into LuaTeX's input stream. -- --- The output is placed into LuaTeX's input stream. +-- ---------------------------------------------------------------------------- -- -------------------------------------------------------------------------------- +-- <file> string; file name +-- <chunksize> integer, multiple of 3; size of binary data (bytes) +-- to be converted at a time +-- <end-of-line string> a string to be appended at the end of every converted +-- chunk; usually a newline should be passed here, or +-- something equivalent, such as "{?nl}" when using the +-- output in a `dvisvgm:raw' \special +-- +-- ============================================================================ -- This work may be distributed and/or modified under the -- conditions of the LaTeX Project Public License. @@ -91,8 +95,12 @@ if (string.find(arg[0],'media4svg%.lua$') and arg[1] ~= nil) then end local filehandle = io.open(foundfile,'rb') if not filehandle then os.exit(1) end + local chunksize=72 + if arg[2] ~= nil then + chunksize= tonumber(arg[2]) + end while true do - local data = filehandle:read(72) + local data = filehandle:read(chunksize) if not data then break end print(base64(data)) end |