fixed EOF bug if no trailing zeros are written, fixed ustar magic check
This commit is contained in:
parent
d4aae06f34
commit
1409eb5fca
|
|
@ -163,6 +163,43 @@ classdef ustar < handle
|
||||||
% fname name of subfile
|
% fname name of subfile
|
||||||
flag = any(ismember(obj.subFile,fname));
|
flag = any(ismember(obj.subFile,fname));
|
||||||
end
|
end
|
||||||
|
function writeIndex(obj,outfile)
|
||||||
|
% obj.writeIndex(outfile)
|
||||||
|
% Write a index file for tar archive in custom '.taridx' format
|
||||||
|
% The format is:
|
||||||
|
% nsubfile int64
|
||||||
|
% [nsubfile times]
|
||||||
|
% subFileName 256*char
|
||||||
|
% subFileBeg int64
|
||||||
|
% subFileSize int64
|
||||||
|
% Input
|
||||||
|
% outfile name of index file to be written (with extension '.taridx')
|
||||||
|
fid = fopen(outfile,'wb');
|
||||||
|
fwrite(fid,obj.NumberOfSubfiles,'int64');
|
||||||
|
for ii=1:obj.NumberOfSubfiles
|
||||||
|
nchar = length(obj.subFile{ii});
|
||||||
|
subfile = blanks(256);
|
||||||
|
subfile(1:nchar) = obj.subFile{ii};
|
||||||
|
subfile(nchar+1) = 0;
|
||||||
|
fwrite(fid,subfile,'256*char');
|
||||||
|
fwrite(fid,obj.subFileBeg(ii),'int64');
|
||||||
|
fwrite(fid,obj.subFileSize(ii),'int64');
|
||||||
|
end
|
||||||
|
fclose(fid);
|
||||||
|
end
|
||||||
|
function [fname,foffset,fsize,nfile] = dumpIndex(obj)
|
||||||
|
% obj.dumpIndex()
|
||||||
|
% Get indexing data of tarfile
|
||||||
|
% Output
|
||||||
|
% fname cell array of file names
|
||||||
|
% foffset data offset within tar file
|
||||||
|
% fsize data size
|
||||||
|
% nfile number of files in archive
|
||||||
|
nfile = obj.NumberOfSubfiles;
|
||||||
|
fname = obj.subFile;
|
||||||
|
foffset = obj.subFileBeg;
|
||||||
|
fsize = obj.subFileSize;
|
||||||
|
end
|
||||||
end
|
end
|
||||||
%% ------------------------------------------------------------------------%%
|
%% ------------------------------------------------------------------------%%
|
||||||
%% PRIVATE METHODS %%
|
%% PRIVATE METHODS %%
|
||||||
|
|
@ -267,6 +304,23 @@ classdef ustar < handle
|
||||||
else % no msgpack decoder available
|
else % no msgpack decoder available
|
||||||
error('No msgpack decoder available.');
|
error('No msgpack decoder available.');
|
||||||
end
|
end
|
||||||
|
case '.taridx'
|
||||||
|
% Open and read file contents (binary)
|
||||||
|
indexfileID = fopen(obj.IndexFile,'rb');
|
||||||
|
if indexfileID<0
|
||||||
|
error('Unable to open file: %s',obj.IndexFile);
|
||||||
|
end
|
||||||
|
fseek(indexfileID,0,'bof');
|
||||||
|
nsubfile = fread(indexfileID,1,'int64=>double');
|
||||||
|
tarFileName = cell(1,nsubfile);
|
||||||
|
tarFileSize = zeros(1,nsubfile);
|
||||||
|
tarFileOffset = zeros(1,nsubfile);
|
||||||
|
for isub=1:nsubfile
|
||||||
|
tarFileName{isub} = deblank(fread(indexfileID,[1,256],'char=>char'));
|
||||||
|
tarFileOffset(isub) = fread(indexfileID,1,'int64=>double');
|
||||||
|
tarFileSize(isub) = fread(indexfileID,1,'int64=>double');
|
||||||
|
end
|
||||||
|
fclose(indexfileID);
|
||||||
otherwise
|
otherwise
|
||||||
error('Unknown file extension of index file: %s',fileExtension);
|
error('Unknown file extension of index file: %s',fileExtension);
|
||||||
end
|
end
|
||||||
|
|
@ -310,7 +364,8 @@ classdef ustar < handle
|
||||||
error('Checksum mismatch! %d,%d',chksum1,chksum2);
|
error('Checksum mismatch! %d,%d',chksum1,chksum2);
|
||||||
end
|
end
|
||||||
% Evaluate magic
|
% Evaluate magic
|
||||||
if ~strcmp(ustar.parseStr(magic),'ustar')
|
%if ~strcmp(ustar.parseStr(magic),'ustar')
|
||||||
|
if isempty(strfind(ustar.parseStr(magic),'ustar'))
|
||||||
error(' Not a UNIX standard tar file.')
|
error(' Not a UNIX standard tar file.')
|
||||||
end
|
end
|
||||||
% Parse header information
|
% Parse header information
|
||||||
|
|
@ -339,6 +394,9 @@ classdef ustar < handle
|
||||||
curPosition = ftell(obj.fileID);
|
curPosition = ftell(obj.fileID);
|
||||||
blockref = zeros(1,obj.blockSize,'int8');
|
blockref = zeros(1,obj.blockSize,'int8');
|
||||||
blockcur = fread(obj.fileID,[1,obj.blockSize],'int8=>int8');
|
blockcur = fread(obj.fileID,[1,obj.blockSize],'int8=>int8');
|
||||||
|
if feof(obj.fileID)
|
||||||
|
isEOF = true;
|
||||||
|
end
|
||||||
if isequal(blockcur,blockref)
|
if isequal(blockcur,blockref)
|
||||||
blockcur = fread(obj.fileID,[1,obj.blockSize],'int8=>int8');
|
blockcur = fread(obj.fileID,[1,obj.blockSize],'int8=>int8');
|
||||||
if isequal(blockcur,blockref)
|
if isequal(blockcur,blockref)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue