ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* new hash for buffer (as file)
@ 2022-09-22 17:25 Pablo Rodriguez via ntg-context
  2022-09-23  4:01 ` Max Chernoff via ntg-context
  0 siblings, 1 reply; 9+ messages in thread
From: Pablo Rodriguez via ntg-context @ 2022-09-22 17:25 UTC (permalink / raw)
  To: ConTeXt users; +Cc: Pablo Rodriguez

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%
    {\cldcontext{utilities.sha2.hash256(io.loaddata("#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
the buffer for "context(utilities.sha2.hash256(io.loaddata(buffer)))".

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.

Many thanks in advance for your help,

Pablo
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

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

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2022-09-26 23:01 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-22 17:25 new hash for buffer (as file) Pablo Rodriguez via ntg-context
2022-09-23  4:01 ` Max Chernoff via ntg-context
2022-09-23 15:06   ` Pablo Rodriguez via ntg-context
2022-09-25 17:59     ` Pablo Rodriguez via ntg-context
2022-09-26  0:05       ` Max Chernoff via ntg-context
2022-09-26  8:47         ` Hans Hagen via ntg-context
2022-09-26 23:01           ` Max Chernoff via ntg-context
2022-09-26 17:24         ` Pablo Rodriguez via ntg-context
2022-09-26 18:07           ` Hans Hagen via ntg-context

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).