classref: Sync with current master branch (811ce36)

This commit is contained in:
Godot Organization
2024-06-29 03:20:27 +00:00
parent 8d4381a956
commit 22eec0f18c
16 changed files with 194 additions and 42 deletions

View File

@@ -40,8 +40,9 @@ The :ref:`HashType<enum_HashingContext_HashType>` enum shows the supported hashi
# 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.
@@ -64,9 +65,10 @@ The :ref:`HashType<enum_HashingContext_HashType>` enum shows the supported hashi
// 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();