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

Pablo Rodriguez oinos at gmx.es
Sun Sep 25 19:59:06 CEST 2022


On 9/23/22 17:06, Pablo Rodriguez via ntg-context wrote:
> On 9/23/22 06:01, Max Chernoff via ntg-context wrote:
>> […]
>>            return utilities.sha2.hash256(
>>                str:gsub(string.char(0x0D), string.char(0x0A))
>>            )
> […]
> this works perfectly fine with Linux "str:gsub('\r','\n')", but I can’t
> make it work in Windows.

Hi again Max,

this seems to solve the issue in Windows too:

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

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

  function sha256(str)
    if os.name == "windows" then
      return utilities.sha2.hash256(str:gsub("\r", "\r\n"))
    else
      return utilities.sha2.hash256(str:gsub("\r", "\n"))
    end
  end
  \stopluacode

  \def\shabuffer#1%
    {\cldcontext{sha256(buffers.raw("#1"))}}

  \def\shafile#1%
    {\cldcontext{utilities.sha2.hash256(io.loaddata("#1"))}}

  \shabuffer{test}

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

  \shafile{temporary-αβγ}

  \stoptext

But now I don’t understand is the following issue: if the saved file
contains "\r\n", why does basic Notepad the new lines?

"\r\n" are the chars to get new lines in Windows. Or what am I missing here?

Many thanks for your help,

Pablo


More information about the ntg-context mailing list