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
2 changes: 1 addition & 1 deletion .github/badges/tests.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 13 additions & 4 deletions code/datatypes/+nansen/+stack/+virtual/Binary.m
Original file line number Diff line number Diff line change
Expand Up @@ -360,16 +360,25 @@ function initializeFile(filePath, arraySize, arrayClass)
numBytes = nansen.stack.ImageStack.getImageDataByteSize(...
arraySize, arrayClass);

% On Windows, fsutil preallocates the file without writing
% its contents. Every other platform, and a failed fsutil
% call, falls back to writing a sparse file with fwrite.
status = 1;
if ispc
[status, ~] = system(sprintf('cmd /C fsutil file createnew %s %i', filePath, numBytes));
elseif ismac
status = 1;
end

if status % Backup solution
fileId = fopen(filePath, 'w');
[fileId, errorMessage] = fopen(filePath, 'w');
if fileId == -1
error('NANSEN:Stack:Binary:FileNotCreated', ...
['Could not create the binary file "%s": %s. ', ...
'Check that the folder exists and is writable.'], ...
filePath, errorMessage)
end
fileCleanup = onCleanup(@() fclose(fileId));
fwrite(fileId, 0, 'uint8', numBytes-1); % 4th arg: skip
fclose(fileId);
clear fileCleanup % Close the file before it is mapped
end

else
Expand Down