Function “calculateWeakChecksum”
function calculateWeakChecksum(path)
Calculates the "weak" checksum for a given file
This function calculates a checksum consisting of the length of the file, as well as a portion of the beginning, the middle and the end of the file's contents. The weak checksum is used for quickly determining possible file duplicates, with a high chance of detecting differences in compressed image files.
However, large uncompressed files may lead to the same checksum even if their image contents differ in parts. To check for proper equality, use the much slower
calculateStrongChecksuminstead.
Parameters
| Name | Type | Description |
|---|---|---|
path | string | Path or URL of the file to read |
Return Value
Returns the weak checksum of the file encoded as a hex string.
Example
if (calculateWeakChecksum("image1.jpg") == calculateWeakChecksum("image2.jpg"))
print("The two files may be identical");
else
print("The two files are not identical");