-
-
Notifications
You must be signed in to change notification settings - Fork 18.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix hashing context example #91920
base: master
Are you sure you want to change the base?
Fix hashing context example #91920
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for contributing to the documentation!
CI is complaining about indentation. Make sure the code is indented with 4 spaces, unlike the rest of the XML file which uses tabs.
Also, the commit is linked to a different GitHub account than the one you used to submit the PR. This is fine, but I wanted to make sure it wasn't by mistake. For more information see: Why are my commits linked to the wrong user?
See which "email" you have configured currently: https://github.com/godotengine/godot/pull/91920.patch
doc/classes/HashingContext.xml
Outdated
while not file.get_position() < file.get_len(): | ||
var remaining = file.get_len() - file.get_position() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The method is called get_length
.
while not file.get_position() < file.get_len(): | |
var remaining = file.get_len() - file.get_position() | |
while not file.get_position() < file.get_length(): | |
var remaining = file.get_length() - file.get_position() |
doc/classes/HashingContext.xml
Outdated
// Update the context after reading each chunk. | ||
while (file.GetPosition() < file.GetLength()) | ||
{ | ||
int remaining = file.GetLen() - file.GetPosition(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These methods return ulong
so you need to cast the result to int
.
int remaining = file.GetLen() - file.GetPosition(); | |
int remaining = (int)(file.GetLength() - file.GetPosition()); |
doc/classes/HashingContext.xml
Outdated
while (file.GetPosition() < file.GetLength()) | ||
{ | ||
int remaining = file.GetLen() - file.GetPosition(); | ||
if (remaining > ChunkSize) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
C# code-style is to add a new line before the curly bracket.
if (remaining > ChunkSize) { | |
if (remaining > ChunkSize) | |
{ |
doc/classes/HashingContext.xml
Outdated
if (remaining > ChunkSize) { | ||
remaining = ChunkSize; | ||
} | ||
ctx.Update(file.GetBuffer(ChunkSize)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To match the GDScript changes:
ctx.Update(file.GetBuffer(ChunkSize)); | |
ctx.Update(file.GetBuffer(Mathf.Min(remaining, ChunkSize))); |
doc/classes/HashingContext.xml
Outdated
# Open the file to hash. | ||
var file = FileAccess.open(path, FileAccess.READ) | ||
# Update the context after reading each chunk. | ||
while not file.get_position() < file.get_len(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
while not file.get_position() < file.get_len(): | |
while file.get_position() < file.get_len(): |
e84a6f7
to
570455b
Compare
Example now works for any file size instead of just multiples of CHUNK_SIZE Example also uses correct method for looping over file data
570455b
to
d6715b4
Compare
The example function produces invalid hashes for files that aren't a multiple of
CHUNK_SIZE
bytes in sizeFixes two issues:
eof_reached()
who's docs say to usefile.get_position() < file.get_len()
instead when loopingCHUNK_SIZE
ifCHUNK_SIZE
would be too large