You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-05 12:10:55 +00:00
Merge pull request #91920 from dmipeck/fix-hashing-context-example
Fix hashing context example
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user