include "filesys.s7i";
include "gzip.s7i";
include "bzip2.s7i";
include "xz.s7i";
include "zstd.s7i";
include "tar.s7i";
include "cpio.s7i";
include "zip.s7i";
include "rpm.s7i";
include "ar.s7i";
const func fileSys: openArchive (inout file: archiveFile) is func
result
var fileSys: archive is fileSys.value;
local
var string: magicBytes is "";
begin
if archiveFile <> STD_NULL then
magicBytes := gets(archiveFile, length(GZIP_MAGIC));
if magicBytes = GZIP_MAGIC then
seek(archiveFile, 1);
archiveFile := openGzipFile(archiveFile, READ);
else
magicBytes &:= gets(archiveFile, length(BZIP2_MAGIC) - length(GZIP_MAGIC));
if magicBytes = BZIP2_MAGIC then
seek(archiveFile, 1);
archiveFile := openBzip2File(archiveFile, READ);
else
magicBytes &:= gets(archiveFile, length(ZSTD_MAGIC) - length(BZIP2_MAGIC));
if magicBytes = ZSTD_MAGIC then
seek(archiveFile, 1);
archiveFile := openZstdFile(archiveFile);
else
magicBytes &:= gets(archiveFile, length(XZ_MAGIC) - length(ZSTD_MAGIC));
seek(archiveFile, 1);
if magicBytes = XZ_MAGIC then
archiveFile := openXzFile(archiveFile);
end if;
end if;
end if;
end if;
archive := openTar(archiveFile);
if archive = fileSys.value then
archive := openCpio(archiveFile);
if archive = fileSys.value then
archive := openZip(archiveFile);
if archive = fileSys.value then
archive := openRpm(archiveFile);
if archive = fileSys.value then
archive := openAr(archiveFile);
end if;
end if;
end if;
end if;
end if;
end func;
const func fileSys: openArchive (in string: archiveFileName) is func
result
var fileSys: archive is fileSys.value;
local
var file: archiveFile is STD_NULL;
begin
archiveFile := open(archiveFileName, "r");
archive := openArchive(archiveFile);
end func;