Home Unix cksum on Windows Machine through Matlab

Unix cksum on Windows Machine through Matlab

Jessica
1#
Jessica Published in 2017-12-07 17:42:20Z
 My company develops products, primarily using Matlab scripts, that gets used by our customer in a RedHat environment we do not have access to. I am trying to figure out a way to to a unix cksum command in Matlab so that when our costumer receives it they can verify that nothing has changed. Edit for clarification: Since the tools used for development are in matlab, the PM would like the Unix cksum function integrated into the creation so that the output of our tool always matches what we deliver to the customer on a Unix system. We've found that a DOS cksum command and a Unix cksum don't give the exact same results
Tommaso Belluzzo
2#
Tommaso Belluzzo Reply to 2017-12-07 19:05:10Z
 So, if your goal is to calculate a *NIX style checksum within the Matlab application itself and you really can't avoid this (for example, calling cksum with unix), the best option you have is to use Java interop within Matlab to achieve this task. Implementing a CRC32 Checksum calculation based exclusively on Matlab built-in functions risks to become a painful task... fortunately, Matlab allows full usage of Java technology within its environment. The following code should perfectly replicate the *NIX cksum command output: function crc32 = CalculateCRC32(file_path) persistent array; if isempty(array) array = javaArray('java.lang.String',0); 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  Use it within your application as follows: crc32 = CalculateCRC32('C:\Path\To\MyFile.something'); 
 You need to login account before you can post.
Processed in 0.309019 second(s) , Gzip On .