Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
KazukiPrzyborowski authored Mar 29, 2024
1 parent 65d9794 commit 5923a2a
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions pycatfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -1010,15 +1010,15 @@ def AppendFileHeader(fp, numfiles, checksumtype="crc32", formatspecs=__file_form
catver = formatspecs[6];
fileheaderver = str(int(catver.replace(".", "")));
fileheader = AppendNullByte(formatspecs[1] + fileheaderver, formatspecs[5]);
catfp.write(fileheader.encode('UTF-8'));
fp.write(fileheader.encode('UTF-8'));
fnumfiles = format(int(numfiles), 'x').lower();
fnumfilesa = AppendNullBytes([fnumfiles, checksumtype], formatspecs[5]);
catfileheadercshex = GetFileChecksum(fileheader + fnumfilesa, checksumtype, False, formatspecs);
catfileheadercshex = GetFileChecksum(fileheader + fnumfilesa, checksumtype, True, formatspecs);
fnumfilesa = fnumfilesa + AppendNullByte(catfileheadercshex, formatspecs[5]);
catfp.write(fnumfilesa.encode('UTF-8'));
fp.write(fnumfilesa.encode('UTF-8'));
try:
catfp.flush();
os.fsync(catfp.fileno());
fp.flush();
os.fsync(fp.fileno());
except io.UnsupportedOperation:
pass;
except AttributeError:
Expand All @@ -1033,13 +1033,14 @@ def AppendFileHeaderWithContent(fp, filevalues=[], extradata=[], filecontent="",
extrasizelen = format(len(extrasizestr), 'x').lower();
catoutlen = len(filevalues) + len(extradata) + 3;
catoutlenhex = format(catoutlen, 'x').lower();
catoutlist = filevalues;
catoutlist.insert(0, catoutlenhex);
catfileoutstr = AppendNullBytes(catoutlist, formatspecs[5]);
catfileoutstr = AppendNullBytes(catoutlist, formatspecs[5]);
if(len(extradata)>0):
catfileoutstr = catfileoutstr + AppendNullBytes(extradata, formatspecs[5]);
catfileoutstr = catfileoutstr + AppendNullByte(checksumtype, formatspecs[5]);
catfileheadercshex = GetFileChecksum(fileheader + fnumfilesa, checksumtype, False, formatspecs);
catfileheadercshex = GetFileChecksum(catfileoutstr, checksumtype, True, formatspecs);
catfilecontentcshex = GetFileChecksum(filecontent, checksumtype, False, formatspecs);
tmpfileoutstr = catfileoutstr + AppendNullBytes([catfileheadercshex, catfilecontentcshex], formatspecs[5]);
catheaersize = format(int(len(tmpfileoutstr) - 1), 'x').lower();
Expand All @@ -1050,8 +1051,8 @@ def AppendFileHeaderWithContent(fp, filevalues=[], extradata=[], filecontent="",
catfileout = catfileoutstrecd + filecontent + nullstrecd;
fp.write(catfileout);
try:
catfp.flush();
os.fsync(catfp.fileno());
fp.flush();
os.fsync(fp.fileno());
except io.UnsupportedOperation:
pass;
except AttributeError:
Expand Down Expand Up @@ -1092,13 +1093,11 @@ def AppendFiles(infiles, fp, dirlistfromtxt=False, filevalues=[], extradata=[],
AppendFileHeader(fp, fnumfiles, checksumtype, formatspecs);
fnumfiles = format(fnumfiles, 'x').lower();
for curfname in GetDirList:
catfhstart = catfp.tell();
catfhstart = fp.tell();
if(re.findall("^[.|/]", curfname)):
fname = curfname;
else:
fname = "./"+curfname;
if(verbose):
VerbosePrintOut(fname);
if(not followlink or followlink is None):
fstatinfo = os.lstat(fname);
else:
Expand Down Expand Up @@ -1228,7 +1227,7 @@ def AppendFiles(infiles, fp, dirlistfromtxt=False, filevalues=[], extradata=[],
fcontents += chunk;
ftypehex = format(ftype, 'x').lower();
catoutlist = [ftypehex, fname, flinkname, fsize, fatime, fmtime, fctime, fbtime, fmode, fwinattributes, fuid, funame, fgid, fgname, fcurfid, fcurinode, flinkcount, fdev_minor, fdev_major, frdev_minor, frdev_major];
fp = AppendFileHeaderWithContent(fp, catoutlist, extradata, fcontent, checksumtype, formatspecs);
fp = AppendFileHeaderWithContent(fp, catoutlist, extradata, fcontents, checksumtype, formatspecs);
fp.seek(0, 0);
return fp;

Expand All @@ -1238,7 +1237,7 @@ def AppendFileToOutFile(infile, outfile, dirlistfromtxt=False, compression="auto
os.unlink(outfile);
if(outfile=="-"):
verbose = False;
catfp = BytesIO();
catfpfp = BytesIO();
elif(hasattr(outfile, "read") or hasattr(outfile, "write")):
catfp = outfile;
elif(re.findall(r"^(ftp|ftps|sftp)\:\/\/", str(outfile))):
Expand Down

0 comments on commit 5923a2a

Please sign in to comment.