Skip to content

Instantly share code, notes, and snippets.

@TommasoBelluzzo
Last active September 9, 2018 22:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TommasoBelluzzo/f2539a11990e75c2d200ce278f29279c to your computer and use it in GitHub Desktop.
Save TommasoBelluzzo/f2539a11990e75c2d200ce278f29279c to your computer and use it in GitHub Desktop.
A script for calculating the CRC32 checksum of a given file.
% [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