tricu

A lazy functional language based on Tree Calculus
Log | Files | Refs | README | LICENSE

main.tri (919B)


      1 !import foundation as B
      2 !import fileio as IO
      3 !import inspection as Inspect
      4 !export main
      5 -- Candidate offline bindings, not imports from the source workspace. Native
      6 -- has OS process authority; --allow-read/--unsafe-io are not accepted.
      7 -- Read once within an explicit byte budget: hash and report use that same value.
      8 main path = IO.io (IO.bind (IO.readBytes path 1048576) (reply : B.matchResult
      9   (problem _ : IO.abortIO ["Read failed" problem])
     10   (bytes _ : B.matchResult
     11     (code _ : IO.abortIO ["Invalid Arboricx bundle" (Inspect.describeError code) code])
     12     (summary _ : IO.bind (IO.sha256Hex bytes 1048576) (digestReply : B.matchResult
     13       (problem _ : IO.abortIO ["Hash failed" problem])
     14       (digest _ : IO.putStr (B.append "arboricx.inspect.v1\nbundle-sha256\t"
     15         (B.append digest (B.append "\n" (Inspect.renderSummary summary)))))
     16       digestReply))
     17     (Inspect.inspectBundle bytes))
     18   reply))