我正在使用SharpZipLib创建tar.gz归档文件,但我需要在文件名前加上一个目录名.也就是说,进入归档的文件看起来像foo.exe
个,但归档需要知道它们是foo-1.0/foo.exe
,所以解压时会创建正确的目录 struct .
输入文件中已有not个名称正确的目录,因此在归档过程中,需要设置名称.
这就是我到目前为止所拥有的:
var archiveName = $"bin/{projectVersion}.tar.gz";
using var archiveStream = File.Create(archiveName);
using var gzipStream = new GZipOutputStream(archiveStream);
using var archive = TarArchive.CreateOutputTarArchive(gzipStream);
archive.RootPath = projectVersion;
foreach (var path in Directory.GetFileSystemEntries(publishPath)) {
var entry = TarEntry.CreateEntryFromFile(path);
entry.Name = $"{projectVersion}/{Path.GetFileName(path)}";
archive.WriteEntry(entry, true);
}
其中projectVersion
=例如"foo-1.0"
.
我希望设置archive.RootPath
或将每个entry.Name
设置为适当的前缀字符串都能完成这项工作,但即使我同时执行这两项操作,当我解压生成的归档文件时,文件只是被转储到当前目录中.
我错过了什么?