# [NTG-context] new hash for buffer (as file)

Pablo Rodriguez oinos at gmx.es
Thu Sep 22 19:25:23 CEST 2022

Dear list,

playing with buffer contents, I have the following file:

\setupinteraction[state=start]
\setupinteractionscreen[option={attachment}]

\startbuffer[test]
just a test
and another one
\stopbuffer

\starttext
\ctxlua{require("util-sha")}

\def\shabuffer#1%
{\cldcontext{utilities.sha2.hash256(buffers.raw("#1"))}}

\def\shafile#1%

\def\shabufferfile#1%
{\cldcontext{utilities.sha2.hash256(buffers.raw("#1"))}}

\shabuffer{test}

\savebuffer[test][temporary-αβγ, prefix=no]

\shafile{temporary-αβγ}

\attachment[buffer=test, name=\shabufferfile{test}, method=hidden]
\stoptext

I mean, to get hash of the file attached to the document, I need to save

But I don’t need to save the buffer to attach it to the PDF document.

My question is how to define \shabufferfile to avoid \savebuffer (only
required to get the hash).

An approach would be the following one. If I’m not totally wrong,
"savebuffer"
(https://github.com/contextgarden/context/blob/main/tex/context/base/mkxl/buff-ini.lmt#L559)
may be just replacing new lines with "\n" in the original buffer
(https://github.com/contextgarden/context/blob/main/tex/context/base/mkxl/buff-ini.lmt#L576).

The function string.replacenewlines() is defined at
https://github.com/contextgarden/context/blob/main/tex/context/base/mkiv/util-str.lua#L1475.

If I’m not totally wrong about savebuffer replacing newlines with "\n",
I wonder how to create a temporary buffer with such a replacement, so
that it could be hashed later.

I hope my question is clear.