Skip to content

Commit d8ffa94

Browse files
committed
file_checksum: use missing
1 parent 2dd0610 commit d8ffa94

5 files changed

Lines changed: 16 additions & 16 deletions

File tree

+stdlib/+dotnet/file_checksum.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
hash = sprintf('%.2x', uint8(inst.Hash));
2424
catch e
2525
dotnetException(e)
26-
hash = '';
26+
hash = missing;
2727
end
2828

2929
fclose(fid);

+stdlib/+java/file_checksum.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
function hash = file_checksum(file, hash_method)
55

66
if strcmpi(hash_method, 'sha256')
7-
hash_method = "SHA-256";
7+
hash_method = 'SHA-256';
88
end
99

1010
file_chunk = 10e6; % arbitrary (bytes) didn't seem to be very sensitive for speed
1111

1212
fid = fopen(file, 'r');
13-
assert(fid > 1, "could not open file %s", file)
13+
assert(fid > 1, 'could not open file %s', file)
1414

1515
try
1616

@@ -27,7 +27,7 @@
2727

2828
catch e
2929
javaException(e)
30-
hash = '';
30+
hash = missing;
3131
end
3232

3333
fclose(fid);

+stdlib/+shell/file_checksum.m

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
function [hash, cmd] = file_checksum(file, hash_method)
33

44
switch lower(hash_method)
5-
case {"sha-256", "sha256"}
5+
case {'sha-256', 'sha256'}
66
if ismac()
77
cmd = sprintf('shasum --algorithm 256 --binary "%s"', file);
88
elseif ispc()
99
cmd = sprintf('CertUtil -hashfile "%s" SHA256', file);
1010
else
1111
cmd = sprintf('sha256sum --binary "%s"', file);
1212
end
13-
case "md5"
13+
case 'md5'
1414
if ismac()
1515
cmd = sprintf('md5 -r "%s"', file);
1616
elseif ispc()
@@ -25,13 +25,13 @@
2525

2626
if s == 0
2727
switch lower(hash_method)
28-
case {"sha-256", "sha256"}
28+
case {'sha-256', 'sha256'}
2929
hash = regexp(m, '^\w{64}','match','once','lineanchors');
30-
case "md5"
30+
case 'md5'
3131
hash = regexp(m, '^\w{32}','match','once','lineanchors');
3232
end
3333
else
34-
hash = '';
34+
hash = missing;
3535
end
3636

3737
end

+stdlib/file_checksum.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
backend (1,:) string = ["java", "dotnet", "shell"]
2020
end
2121

22-
r = '';
22+
r = missing;
2323

2424
for b = backend
2525
switch b
@@ -33,7 +33,7 @@
3333
error('stdlib:file_checksum:ValueError', 'Unknown backend: %s', b)
3434
end
3535

36-
if ~isempty(r)
36+
if ~ismissing(r)
3737
return
3838
end
3939
end

test/TestHash.m

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,29 +41,29 @@ function test_hash_text(tc, Ph, backend)
4141

4242
[r, b] = stdlib.file_checksum(tc.file, Ph{1}, backend);
4343
tc.assertMatches(b, backend)
44-
tc.verifyClass(r, 'char')
4544

4645
if ismember(backend, stdlib.Backend().select('file_checksum'))
46+
tc.verifyClass(r, 'char')
4747
tc.verifyEqual(r, Ph{2})
4848
else
49-
tc.assertEmpty(r)
49+
tc.assertEqual(r, missing)
5050
end
5151
end
5252

5353

5454
function test_hash_empty(tc, Pe, backend)
5555

5656
r = stdlib.file_checksum(tc.empty, Pe{1}, backend);
57-
tc.verifyClass(r, 'char')
5857

5958
if ismember(backend, stdlib.Backend().select('file_checksum'))
6059
if ispc() && strcmp(backend, 'shell')
61-
tc.verifyEmpty(r)
60+
tc.verifyEqual(r, missing)
6261
else
62+
tc.verifyClass(r, 'char')
6363
tc.verifyEqual(r, Pe{2})
6464
end
6565
else
66-
tc.assertEmpty(r)
66+
tc.assertEqual(r, missing)
6767
end
6868
end
6969

0 commit comments

Comments
 (0)