如何在golang中的tar文件中放置一个tar文件

时间:2017-04-27 04:57:49

标签: go

我想创建一个tar文件,在tar文件中我想放置其他tar文件。层次结构类似

TopLevelTar.tar.gz
    |-->primary/primary.tar
    |-->secondary/secondaty.tar
    |-->tertiary/tertiary.tar

我怎样才能在golag中做到?

2 个答案:

答案 0 :(得分:3)

我认为这可能会对你有所帮助。 基本上,此解决方案是从多个文件创建tarball。您必须简单地提供文件的路径来代替 a.go和b.go等。

  public ActionResult CreateFiles(long? clientId, long? freelancerId)
        {
            string apiEventCommon = string.Format("api/client/{0}/Event/Common", UserSession.ClientId);
            EventCommon eventCommon = HttpHandler.Get<EventCommon>(apiEventCommon, UserSession.AccessToken);
            FileInfoModel createFiles = new FileInfoModel();
            createFiles.AllFiles = eventCommon.FileTypes;
            createFiles.ClientId = Convert.ToInt64(UserSession.ClientId);
            createFiles.FreelancerId = 9;//hardcoded 
            clientId = createFiles.ClientId;//temp
            freelancerId = 9;//temp
            if (clientId != null && freelancerId != null)
            {
                string api = string.Format("api/client/{0}/freelancer/{1}/files", clientId, freelancerId);
                var fileDetail = HttpHandler.Get<List<FilesDetails>>(api, UserSession.AccessToken);
                createFiles.ExistingFiles = fileDetail;
            }
            return View(createFiles);
        }

答案 1 :(得分:0)

我认为它不会以这种方式工作。 Gzip只包含一个文件,tar是将许多文件序列化为一个文件的实用程序。因此这两个util一起使用。通常,您可以将所有文件合并为一个:

tar cvf file.tar primary/primary.txt secondary/second.wtf etc/other.file

而不是用gzip压缩这个文件

gzip file.tar

太棒了。但gzipped可能只是一个文件。当然可以创建许多档案,比如primary / primary.tar和tar档案,然后gzip,但会有点混乱。