Example #1
0
 public void WriteEntry(TarEntry entry, bool recurse)
 {
     string path = null;
     string file = entry.File;
     if ((file == null) || (file.Length == 0))
     {
         entry = TarEntry.CreateTarEntry(entry.Name);
     }
     else
     {
         string name = entry.Name;
         entry = TarEntry.CreateEntryFromFile(file);
         entry.Name = name;
     }
     if (this.verbose)
     {
         this.OnProgressMessageEvent(entry.Name);
     }
     if ((this.asciiTranslate && !entry.IsDirectory) && !this.IsBinary(file))
     {
         path = Path.GetTempFileName();
         StreamReader reader = File.OpenText(file);
         Stream stream = new BufferedStream(File.Create(path));
         while (true)
         {
             string s = reader.ReadLine();
             if (s == null)
             {
                 break;
             }
             byte[] bytes = Encoding.ASCII.GetBytes(s);
             stream.Write(bytes, 0, bytes.Length);
             stream.WriteByte(10);
         }
         reader.Close();
         stream.Flush();
         stream.Close();
         entry.Size = new FileInfo(path).Length;
         file = path;
     }
     string str5 = null;
     if ((this.rootPath != null) && entry.Name.StartsWith(this.rootPath))
     {
         str5 = entry.Name.Substring(this.rootPath.Length + 1);
     }
     if (this.pathPrefix != null)
     {
         str5 = (str5 == null) ? (this.pathPrefix + "/" + entry.Name) : (this.pathPrefix + "/" + str5);
     }
     if (str5 != null)
     {
         entry.Name = str5;
     }
     this.tarOut.PutNextEntry(entry);
     if (entry.IsDirectory)
     {
         if (recurse)
         {
             TarEntry[] directoryEntries = entry.GetDirectoryEntries();
             for (int i = 0; i < directoryEntries.Length; i++)
             {
                 this.WriteEntry(directoryEntries[i], recurse);
             }
         }
     }
     else
     {
         Stream stream2 = File.OpenRead(file);
         int num2 = 0;
         byte[] buffer = new byte[0x8000];
         while (true)
         {
             int count = stream2.Read(buffer, 0, buffer.Length);
             if (count <= 0)
             {
                 break;
             }
             this.tarOut.Write(buffer, 0, count);
             num2 += count;
         }
         Console.WriteLine("written " + num2 + " bytes");
         stream2.Close();
         if ((path != null) && (path.Length > 0))
         {
             File.Delete(path);
         }
         this.tarOut.CloseEntry();
     }
 }