Skip to content

Instantly share code, notes, and snippets.

@TommasoBelluzzo

TommasoBelluzzo/crc32.m

Last active Sep 9, 2018
Embed
What would you like to do?
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