Пример #1
0
 private void WriteEntryCore(TarEntry sourceEntry, bool recurse)
 {
     string path = null;
     string file = sourceEntry.File;
     TarEntry entry = (TarEntry)sourceEntry.Clone();
     if (applyUserInfoOverrides)
     {
         entry.GroupId = _groupId;
         entry.GroupName = groupName;
         entry.UserId = _userId;
         entry.UserName = _userName;
     }
     OnProgressMessageEvent(entry, null);
     if ((asciiTranslate && !entry.IsDirectory) && !IsBinary(file))
     {
         path = Path.GetTempFileName();
         using (StreamReader reader = File.OpenText(file))
         {
             using (Stream stream = File.Create(path))
             {
                 Label_0088:
                 string str3 = reader.ReadLine();
                 if (str3 != null)
                 {
                     byte[] bytes = Encoding.ASCII.GetBytes(str3);
                     stream.Write(bytes, 0, bytes.Length);
                     stream.WriteByte(10);
                     goto Label_0088;
                 }
                 stream.Flush();
             }
         }
         entry.Size = new FileInfo(path).Length;
         file = path;
     }
     string str4 = null;
     if ((rootPath != null) && entry.Name.StartsWith(rootPath))
     {
         str4 = entry.Name.Substring(rootPath.Length + 1);
     }
     if (pathPrefix != null)
     {
         str4 = (str4 == null) ? (pathPrefix + "/" + entry.Name) : (pathPrefix + "/" + str4);
     }
     if (str4 != null)
     {
         entry.Name = str4;
     }
     tarOut.PutNextEntry(entry);
     if (entry.IsDirectory)
     {
         if (recurse)
         {
             TarEntry[] directoryEntries = entry.GetDirectoryEntries();
             for (int i = 0; i < directoryEntries.Length; i++)
             {
                 WriteEntryCore(directoryEntries[i], true);
             }
             return;
         }
         return;
     }
     using (Stream stream2 = File.OpenRead(file))
     {
         byte[] buffer = new byte[0x8000];
         while (true)
         {
             int count = stream2.Read(buffer, 0, buffer.Length);
             if (count <= 0)
             {
                 goto Label_01F6;
             }
             tarOut.Write(buffer, 0, count);
         }
     }
     Label_01F6:
     if (!string.IsNullOrEmpty(path))
     {
         File.Delete(path);
     }
     tarOut.CloseEntry();
 }