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; fname = obj.subFile;
fsize = obj.subFileSize; fsize = obj.subFileSize;
end end
function extract(obj,fname) function extract(obj,fname,varargin)
% obj.extract(fname) % obj.extract(fname)
% Extracts the requested subfile to a standalone file. % Extracts the requested subfile to a standalone file.
% Input % Input
% fname name of subfile % 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); idx = obj.findSubfile(fname);
fbeg = obj.subFileBeg(idx); fbeg = obj.subFileBeg(idx);
fsize = obj.subFileSize(idx); fsize = obj.subFileSize(idx);
fidw = fopen(fname,'w'); fidw = fopen(outfile,'w');
fseek(obj.fileID,fbeg,'bof'); fseek(obj.fileID,fbeg,'bof');
% Chunk the file % Chunk the file
nchunk = ceil(fsize/obj.extrBuffSize); nchunk = ceil(fsize/obj.extrBuffSize);
nchunkFull = floor(fsize/obj.extrBuffSize); nchunkFull = floor(fsize/obj.extrBuffSize);
nchunkPart = nchunk-nchunkFull; nchunkPart = nchunk-nchunkFull;
for ichunk=1:nchunkFull for ichunk=1:nchunkFull
buff = fread(obj.fileID,[1,obj.extrBuffSize],'char=>char'); buff = fread(obj.fileID,[1,obj.extrBuffSize],'*uint8');
fwrite(fidw,buff,'char'); fwrite(fidw,buff);
end end
if nchunkPart>0 if nchunkPart>0
sizeChunkPart = mod(fsize,obj.extrBuffSize); sizeChunkPart = mod(fsize,obj.extrBuffSize);
buff = fread(obj.fileID,[1,sizeChunkPart],'char=>char'); buff = fread(obj.fileID,[1,sizeChunkPart],'*uint8');
fwrite(fidw,buff,'char'); fwrite(fidw,buff);
end end
fclose(fidw); fclose(fidw);
end end