fixed extraction routine

This commit is contained in:
Michael Stumpf (ifhcluster) 2019-09-10 14:38:31 +02:00
parent f580a9378e
commit 06ad37679f
1 changed files with 12 additions and 6 deletions

View File

@ -106,28 +106,34 @@ classdef ustar < handle
fname = obj.subFile;
fsize = obj.subFileSize;
end
function extract(obj,fname)
function extract(obj,fname,varargin)
% obj.extract(fname)
% Extracts the requested subfile to a standalone file.
% Input
% fname name of subfile
% ? outfile path of output file (default: fname)
par = inputParser;
addParamValue(par,'outfile',fname,@ischar);
parse(par,varargin{:});
outfile = par.Results.outfile;
idx = obj.findSubfile(fname);
fbeg = obj.subFileBeg(idx);
fsize = obj.subFileSize(idx);
fidw = fopen(fname,'w');
fidw = fopen(outfile,'w');
fseek(obj.fileID,fbeg,'bof');
% Chunk the file
nchunk = ceil(fsize/obj.extrBuffSize);
nchunkFull = floor(fsize/obj.extrBuffSize);
nchunkPart = nchunk-nchunkFull;
for ichunk=1:nchunkFull
buff = fread(obj.fileID,[1,obj.extrBuffSize],'char=>char');
fwrite(fidw,buff,'char');
buff = fread(obj.fileID,[1,obj.extrBuffSize],'*uint8');
fwrite(fidw,buff);
end
if nchunkPart>0
sizeChunkPart = mod(fsize,obj.extrBuffSize);
buff = fread(obj.fileID,[1,sizeChunkPart],'char=>char');
fwrite(fidw,buff,'char');
buff = fread(obj.fileID,[1,sizeChunkPart],'*uint8');
fwrite(fidw,buff);
end
fclose(fidw);
end