Last active
September 9, 2018 22:17
-
-
Save TommasoBelluzzo/f2539a11990e75c2d200ce278f29279c to your computer and use it in GitHub Desktop.
A script for calculating the CRC32 checksum of a given file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% [INPUT] | |
% file_path = A char array representing the file path. | |
% | |
% [OUTPUT] | |
% crc32 = A char array representing the CRC32 Checksum of the file. | |
function crc32 = calculate_crc32(file_path) | |
persistent array; | |
if isempty(array) | |
array = javaArray('java.lang.String',0); | |
end | |
if (exist(file_path,'file') ~= 2) | |
error('The specified file does not exist.'); | |
end | |
import('java.lang.Long'); | |
import('java.nio.file.Files'); | |
import('java.nio.file.Paths'); | |
import('java.util.zip.CRC32'); | |
path = Paths.get(file_path,array); | |
data = Files.readAllBytes(path); | |
provider = java.util.zip.CRC32(); | |
provider.update(data); | |
crc32 = char(Long.toHexString(provider.getValue())); | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment