Skip to content

Commit

Permalink
issue-16: Replaced util function with built-in function fileparts
Browse files Browse the repository at this point in the history
  • Loading branch information
IslaL committed Apr 18, 2024
1 parent f0b79e6 commit f2eddac
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 24 deletions.
10 changes: 4 additions & 6 deletions onc/+onc/DataProductFile.m
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,13 @@

% Obtain filesize from headers, or fallback to body string length
lengthData = response.getFields('Content-Length');
[~, ~, ext] = fileparts(filename);
if length(lengthData) == 1
this.fileSize = str2double(lengthData.Value);
elseif strcmp(ext, '.xml')
this.fileSize = length(xmlwrite(response.Body.Data));
else
ext = util.extractFileExtension(filename);
if strcmp(ext, 'xml')
this.fileSize = length(xmlwrite(response.Body.Data));
else
this.fileSize = strlength(response.Body.Data);
end
this.fileSize = strlength(response.Body.Data);
end
try
saveResult = util.save_as_file(response.Body.Data, outPath, filename, 'overwrite', overwrite);
Expand Down
13 changes: 0 additions & 13 deletions onc/+util/extractFileExtension.m

This file was deleted.

8 changes: 3 additions & 5 deletions onc/+util/save_as_file.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,11 @@
try
matlabVersion = version('-release');
year = str2double(matlabVersion(1:end-1));

ext = util.extractFileExtension(fileName);

[~, ~, ext] = fileparts(fileName);
% if result is an image file or .xml file, use other save methods instead of fwrite.
if strcmp(ext, 'png') || strcmp(ext, 'jpg')
if strcmp(ext, '.png') || strcmp(ext, '.jpg')
imwrite(dataToWrite, fullPath);
elseif strcmp(ext, 'xml')
elseif strcmp(ext, '.xml')
xmlwrite(fullPath, dataToWrite);
else
% open output file
Expand Down

0 comments on commit f2eddac

Please sign in to comment.