Dear list,

I need to add checksums to files I attach to PDF documents.

Following the suggestion from https://stackoverflow.com/a/326715, I wrote:

    \starttext
    \startluacode
    function document.capture(cmd, raw)
        local f = assert(io.popen(cmd, 'r'))
        local s = assert(f:read('*a'))
        f:close()
        if raw then return s end
        s = string.gsub(s, '^%s+', '')
        s = string.gsub(s, '%s+$', '')
        s = string.gsub(s, '[\n\r]+', ' ')
        return s
    end

    function document.sha256(file)
        command_output= document.capture("sha256sum -b " .. file)
        context(command_output:sub(0,64))
    end

    function document.sha512(file)
        command_output= document.capture("sha512sum -b " .. file)
        context(command_output:sub(0,128))
    end
    \stopluacode

    \def\shatwo#1%
        {\ctxlua{document.sha256("#1")}}

    \def\shafive#1%
        {\ctxlua{document.sha512("#1")}}

    \shatwo{Desktop/i-context.pdf}

    \shafive{i-context.pdf}
    \stoptext

Directories are a problem here. I mean, \shatwo{Desktop/i-context.pdf}
cannot work in Windows.

Which would be the way to make it work in Windows?

Many thanks for your help,

Pablo
-- 
http://www.ousia.tk
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

Reply via email to