; Sha256FileBytes Example
; -----------------------

; Write a small save-game file to fingerprint
WriteTextAtomic "sha_bytes_example.json","{}"
Print "Wrote sha_bytes_example.json"
Print ""

; Sha256FileBytes returns the digest as a new owned 32-byte Bank
; (zero with FilesystemError diagnostics on failure)
digest=Sha256FileBytes("sha_bytes_example.json")
If digest=0 Then RuntimeError FilesystemError()

Print "Digest Bank size: "+BankSize(digest)+" bytes (always 32)"

; Show the raw bytes as hex - it matches Sha256File's hex output
hex_text$=""
For i=0 To BankSize(digest)-1
    hex_text=hex_text+Right(Hex(PeekByte(digest,i)),2)
Next
Print "Digest bytes:      "+Lower(hex_text)
Print "Sha256File gives:  "+Sha256File("sha_bytes_example.json")

; The digest Bank is owned by us and must be freed
FreeBank digest

; Clean up the file this example created
DeleteFile "sha_bytes_example.json"

Print ""
Print "Press any key to close the example"
WaitKey

End
