hash for buffer contents
![](https://secure.gravatar.com/avatar/5955e8e90611e77ccbfc7721b6112027.jpg?s=120&d=mm&r=g)
Dear list, I have the following sample: \ctxlua{require("util-sha")} \starttext \startbuffer[abc] samples \stopbuffer \cldcontext{utilities.sha2.hash512("buffer-name")} \stoptext Is there any way to get "utilities.sha2.hash512" with the contents of the "abc" buffer? Many thanks for your help, Pablo
![](https://secure.gravatar.com/avatar/413051f5ef37416e8bd7c228ea721eb9.jpg?s=120&d=mm&r=g)
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": \startbuffer[test] One Two Three \stopbuffer[test] \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. -- Max
![](https://secure.gravatar.com/avatar/5955e8e90611e77ccbfc7721b6112027.jpg?s=120&d=mm&r=g)
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
participants (2)
-
Max Chernoff
-
Pablo Rodriguez