[NTG-context] hash for buffer contents

Pablo Rodriguez oinos at gmx.es
Thu Sep 22 17:50:28 CEST 2022


On 9/22/22 00:26, Max Chernoff via ntg-context wrote:
> Hi Pablo,
>
>> Is there any way to get "utilities.sha2.hash512" with the contents of
>> the "abc" buffer?
>
> You can use "buffers.getcontent" or "buffers.raw":

Many thanks for your reply, Max.

This is exactly what I needed.

>    \starttext
>    \startluacode
>        require("util-sha")
>
>        local content = buffers.getcontent("test")
>        -- local content = buffers.raw("test") -- same result
>        local sha512 = utilities.sha2.hash512(content)
>        context(sha512)
>    \stopluacode
>    \stoptext
>
> Depending on what you're trying to do, the "filter" module may be
> helpful here.

I think the following function is just fine for me:

  \startbuffer[test]
  just a test
  \stopbuffer

  \starttext
  \startluacode
    require("util-sha")

    function document.sha512buffer(buffer)
      return utilities.sha2.hash512(buffers.raw(buffer))
    end
  \stopluacode

  \def\shabuffer#1
    {\cldcontext{document.sha512buffer("#1")}}

  \shabuffer{test}

  \stoptext

Many thanks for your help again,

Pablo


More information about the ntg-context mailing list