diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2024-06-27 10:05:50 +0200 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2024-06-27 10:05:50 +0200 |
commit | 51a6bc1f11b11fb13deb0ad57eea2001175b6935 (patch) | |
tree | 7c00ed5747f80acf507704d5580731e6152af10b | |
parent | 374807f427eec5ee7caebfc509a158fe715a6bfe (diff) | |
parent | d6715b4cdec889b503732ff0df963b3abea081d5 (diff) | |
download | redot-engine-51a6bc1f11b11fb13deb0ad57eea2001175b6935.tar.gz |
Merge pull request #91920 from dmipeck/fix-hashing-context-example
Fix hashing context example
-rw-r--r-- | doc/classes/HashingContext.xml | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/doc/classes/HashingContext.xml b/doc/classes/HashingContext.xml index f2681ae7b3..b42acb2b99 100644 --- a/doc/classes/HashingContext.xml +++ b/doc/classes/HashingContext.xml @@ -20,8 +20,9 @@ # Open the file to hash. var file = FileAccess.open(path, FileAccess.READ) # Update the context after reading each chunk. - while not file.eof_reached(): - ctx.update(file.get_buffer(CHUNK_SIZE)) + while file.get_position() < file.get_length(): + var remaining = file.get_length() - file.get_position() + ctx.update(file.get_buffer(min(remaining, CHUNK_SIZE))) # Get the computed hash. var res = ctx.finish() # Print the result as hex string and array. @@ -43,9 +44,10 @@ // Open the file to hash. using var file = FileAccess.Open(path, FileAccess.ModeFlags.Read); // Update the context after reading each chunk. - while (!file.EofReached()) + while (file.GetPosition() < file.GetLength()) { - ctx.Update(file.GetBuffer(ChunkSize)); + int remaining = (int)(file.GetLength() - file.GetPosition()); + ctx.Update(file.GetBuffer(Mathf.Min(remaining, ChunkSize))); } // Get the computed hash. byte[] res = ctx.Finish(); |