Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/did/+did/+file/fileobj.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
fid (1,1) double = -1

% permission - The file permission
permission (1,:) char {did.file.mustBeValidPermission} = 'r'
permission (1,:) char {did.file.mustBeValidPermission} = 'rb'

% machineformat - big-endian ('b'), little-endian ('l'), or native ('n')
machineformat (1,:) char {did.file.mustBeValidMachineFormat} = 'n'
Expand All @@ -30,7 +30,7 @@
% then the filename is stored.
arguments
propValues.machineformat (1,1) string {did.file.mustBeValidMachineFormat} = 'n'; % native machine format
propValues.permission (1,1) string {did.file.mustBeValidPermission} = "r"
propValues.permission (1,1) string {did.file.mustBeValidPermission} = "rb"
propValues.fid (1,1) int64 = -1
propValues.fullpathfilename = '';
end
Expand Down Expand Up @@ -207,7 +207,7 @@ function frewind(fileobj_obj)
%
% See also: FWRITE

if strcmpi(fileobj_obj.permission,'r')
if strcmpi(fileobj_obj.permission(1),'r')
error('DID:File:Fileobj','Cannot use fwrite() method with read-only file');
end

Expand All @@ -233,7 +233,7 @@ function frewind(fileobj_obj)
% [DATA,COUNT] = FREAD(FILEOBJ_OBJ, COUNT, [PRECISION], [SKIP], [MACHINEFORMAT])
%
% Attempts to read COUNT elements with resolution PRECISION. If PRECISION is not
% provided, then 'char' is assumed. If SKIP is provided, then SKIP is in number of bytes, unless
% provided, then 'uint8' is assumed. If SKIP is provided, then SKIP is in number of bytes, unless
% PRECISION is in bits, in which case SKIP is in bits. MACHINEFORMAT is the machine format to use.
%
% See FREAD for a full description of these input arguments.
Expand All @@ -243,7 +243,7 @@ function frewind(fileobj_obj)
data = [];

if nargin<3
precision = 'char';
precision = 'uint8';
end
if nargin<4
skip = 0;
Expand Down Expand Up @@ -344,7 +344,7 @@ function frewind(fileobj_obj)
varargin
end

if strcmpi(fileobj_obj.permission,'r')
if strcmpi(fileobj_obj.permission(1),'r')
error('DID:File:Fileobj','Cannot use fprintf() method with read-only file');
end
count = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/did/+did/+file/mustBeValidPermission.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ function mustBeValidPermission(value)

permissionsAsString = strjoin( " " + VALID_PERMISSIONS, newline);

% Add text modes:
VALID_PERMISSIONS = [VALID_PERMISSIONS, insertAfter(VALID_PERMISSIONS, 1, "t")];
% Add text and binary modes:
VALID_PERMISSIONS = [VALID_PERMISSIONS, insertAfter(VALID_PERMISSIONS, 1, "t"), insertAfter(VALID_PERMISSIONS, 1, "b")];

assert(ismember(value, VALID_PERMISSIONS), ...
'File permission must be one of:\n%s\n', permissionsAsString)
Expand Down
10 changes: 5 additions & 5 deletions src/did/+did/+file/readonly_fileobj.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
% then the filename is stored.
arguments
options.machineformat (1,1) string {did.file.mustBeValidMachineFormat} = 'n'; % native machine format
options.permission (1,1) string {did.file.mustBeValidPermission} = "r"
options.permission (1,1) string {did.file.mustBeValidPermission} = "rb"
options.fid (1,1) int64 = -1
options.fullpathfilename = '';
end
Expand All @@ -29,7 +29,7 @@

% Ensure that the default 'r' permission was not modified
if ~strcmpi(fileobj_obj.permission(1),'r')
error('DID:File:ReadOnly_Fileobj','Read-only file must have ''r'' permission');
error('DID:File:ReadOnly_Fileobj','Read-only file must have ''rb'' permission');
end
end % readonly_fileobj() constructor

Expand All @@ -42,10 +42,10 @@
%
% See also: FOPEN, FILEOBJ/FOPEN, FILEOBJ/FCLOSE, FCLOSE

if nargin > 1 && ~strcmpi(permission,'r')
error('DID:File:ReadOnly_Fileobj','Read-only file must be opened with ''r'' permission');
if nargin > 1 && ~strcmpi(permission,'rb')
error('DID:File:ReadOnly_Fileobj','Read-only file must be opened with ''rb'' permission');
end
fileobj_obj = fopen@did.file.fileobj(fileobj_obj,'r',varargin{:});
fileobj_obj = fopen@did.file.fileobj(fileobj_obj,'rb',varargin{:});
end %fopen
end % methods

Expand Down
2 changes: 1 addition & 1 deletion src/did/+did/+implementations/binarydoc_matfid.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
% the database.
%
binarydoc_matfid_obj.fclose@did.file.fileobj();
binarydoc_matfid_obj.permission = 'r';
binarydoc_matfid_obj.permission = 'rb';
end % fclose()
end
end
2 changes: 1 addition & 1 deletion tests/+did/+unittest/test_fileobj.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ function test_constructor(testCase)
% Test creating a fileobj
theFileObj = did.file.fileobj();
testCase.verifyEqual(theFileObj.fid, -1);
testCase.verifyEqual(theFileObj.permission, 'r');
testCase.verifyEqual(theFileObj.permission, 'rb');
testCase.verifyEqual(theFileObj.machineformat, 'n');
testCase.verifyEqual(theFileObj.fullpathfilename, '');
end
Expand Down
Loading