Skip to content

Commit de2ec24

Browse files
committed
add fileio.sha256sum
1 parent 47aee56 commit de2ec24

File tree

5 files changed

+44
-8
lines changed

5 files changed

+44
-8
lines changed

+stdlib/+fileio/extract_zstd.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ function extract_zstd(archive, out_dir)
99
out_dir (1,1) string
1010
end
1111

12-
archive = stdlib.fileio.expanduser(archive);
12+
import stdlib.fileio.expanduser
13+
14+
archive = expanduser(archive);
1315

1416
assert(isfile(archive), "%s is not a file", archive)
1517

+stdlib/+fileio/is_absolute_path.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
apath string
99
end
1010

11-
apath = stdlib.fileio.expanduser(apath);
11+
import stdlib.fileio.expanduser
12+
13+
apath = expanduser(apath);
1214

1315
if ispc
1416
i = strlength(apath) < 3;

+stdlib/+fileio/md5sum.m

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,13 @@
44
file (1,1) string
55
end
66

7-
file = stdlib.fileio.expanduser(file);
7+
import stdlib.fileio.expanduser
88

9+
file = expanduser(file);
910
assert(isfile(file), '%s not found', file)
1011

1112
hash = string.empty;
1213

13-
if verLessThan('matlab', '9.7')
14-
return
15-
end
16-
1714
if ismac
1815
[stat,hash] = system("md5 -r " + file);
1916
elseif isunix

+stdlib/+fileio/samepath.m

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,8 @@
22
%% issame = samepath(path1, path)
33
% true if inputs resolve to same path
44

5-
issame = gemini3d.fileio.absolute_path(path1) == gemini3d.fileio.absolute_path(path2);
5+
import stdlib.fileio.absolute_path
6+
7+
issame = absolute_path(path1) == absolute_path(path2);
8+
69
end

+stdlib/+fileio/sha256sum.m

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
function hash = sha256sum(file)
2+
% compute sha256 hash of file
3+
arguments
4+
file (1,1) string
5+
end
6+
7+
import stdlib.fileio.expanduser
8+
9+
file = expanduser(file);
10+
assert(isfile(file), '%s not found', file)
11+
12+
hash = string.empty;
13+
14+
if ismac
15+
[stat,hash] = system("shasum --algorithm 256 --binary " + file);
16+
elseif isunix
17+
[stat,hash] = system("sha256sum --binary " + file);
18+
elseif ispc
19+
[stat,hash] = system("CertUtil -hashfile " + file + " SHA256");
20+
else
21+
return
22+
end
23+
24+
if stat ~= 0
25+
return
26+
end
27+
28+
hash = regexp(hash,'^\w{64}','match','once','lineanchors');
29+
30+
assert(strlength(hash)==64, 'SHA256 hash is 64 characters')
31+
32+
end % function

0 commit comments

Comments
 (0)